Logo Search packages:      
Sourcecode: libmpdclient version File versions  Download package

mpd_malloc struct mpd_connection* mpd_connection_new_async ( struct mpd_async async,
const char *  welcome 
) [read]

Creates a mpd_connection object based on an existing asynchronous MPD connection. You should not continue to use the mpd_async object. Note that mpd_connection_free() also frees your mpd_async object!

This function does not block at all, which is why you have to pass the welcome message to it.

Parameters:
async a mpd_async instance
welcome the first line sent by MPD (the welcome message)
Returns:
a mpd_connection object, or NULL on out-of-memory

Definition at line 264 of file connection.c.

References mpd_connection::async, mpd_connection::error, mpd_connection_new_async(), MPD_ERROR_OOM, mpd_connection::pair_state, mpd_connection::PAIR_STATE_NONE, mpd_connection::parser, mpd_connection::receiving, mpd_connection::request, mpd_connection::sending_command_list, and mpd_connection::timeout.

Referenced by mpd_connection_new_async().

{
      struct mpd_connection *connection = malloc(sizeof(*connection));

      assert(async != NULL);
      assert(welcome != NULL);

      if (connection == NULL)
            return NULL;

      mpd_error_init(&connection->error);
      connection->async = async;
      connection->timeout.tv_sec = 30;
      connection->timeout.tv_usec = 0;
      connection->parser = NULL;
      connection->receiving = false;
      connection->sending_command_list = false;
      connection->pair_state = PAIR_STATE_NONE;
      connection->request = NULL;

      if (!mpd_socket_global_init(&connection->error))
            return connection;

      connection->parser = mpd_parser_new();
      if (connection->parser == NULL) {
            mpd_error_code(&connection->error, MPD_ERROR_OOM);
            return connection;
      }

      mpd_parse_welcome(connection, welcome);

      return connection;
}


Generated by  Doxygen 1.6.0   Back to index