libmpdclient 2.22
|
#include <connection.h>
This opaque object represents a connection to a MPD server. Call mpd_connection_new() to create a new instance. To free an instance, call mpd_connection_free(). Example:
struct mpd_connection *conn = mpd_connection_new(NULL, 0, 0); // error handling if (conn == NULL) { fprintf(stderr, "Out of memory\n"); return; } if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS) { fprintf(stderr, "%s\n", mpd_connection_get_error_message(c)); mpd_connection_free(c); return; } // we can now use the connection mpd_run_next(conn); // close the connection and free memory mpd_connection_free(conn);
Error handling: most functions return a bool
indicating success or failure. In this case, you may query the nature of the error with the functions mpd_connection_get_error(), mpd_connection_get_error_message(), mpd_connection_get_server_error().
Some errors can be cleared by calling mpd_connection_clear_error(), like MPD_ERROR_SERVER, MPD_ERROR_ARGUMENT. Most others are fatal, and cannot be recovered, like MPD_ERROR_CLOSED - mpd_connection_clear_error() returns false.
Some functions like mpd_recv_pair() cannot differentiate between "end of response" and "error". If this function returns NULL
, you have to check mpd_connection_get_error().
To integrate this object in a non-blocking event I/O loop, use mpd_connection_get_fd() to obtain the underlying socket descriptor.