diff options
author | Kalle Wallin <kaw@linux.se> | 2004-03-20 08:46:30 +0000 |
---|---|---|
committer | Kalle Wallin <kaw@linux.se> | 2004-03-20 08:46:30 +0000 |
commit | 6c0042b0c87fe601b9ad606d4ee44305fc36d2cb (patch) | |
tree | c3126623b9d7166939a7db08df1f9d643818474c | |
parent | 47c1290110009e23749e0be9d547c4d5b9fcba30 (diff) | |
download | mpd-6c0042b0c87fe601b9ad606d4ee44305fc36d2cb.tar.gz mpd-6c0042b0c87fe601b9ad606d4ee44305fc36d2cb.tar.xz mpd-6c0042b0c87fe601b9ad606d4ee44305fc36d2cb.zip |
Added function mpc_reconnect().
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@323 09075e82-0dd4-0310-85a5-a0d7c8717e4f
-rw-r--r-- | mpc.c | 40 |
1 files changed, 38 insertions, 2 deletions
@@ -23,6 +23,9 @@ mpc_update_song(mpd_client_t *c) { mpd_InfoEntity *entity; + if( mpc_error(c) ) + return; + if( c->song ) { mpd_freeSong(c->song); @@ -30,6 +33,8 @@ mpc_update_song(mpd_client_t *c) } mpd_sendPlaylistInfoCommand(c->connection, c->status->song); + if( mpc_error(c) ) + return; while( (entity=mpd_getNextInfoEntity(c->connection)) ) { mpd_Song *song = entity->info.song; @@ -84,6 +89,26 @@ mpc_connect(char *host, int port) } int +mpc_reconnect(mpd_client_t *c, char *host, int port) +{ + mpd_Connection *connection; + + connection = mpd_newConnection(host, port, 10); + if( connection==NULL ) + return -1; + if( connection->error ) + { + mpd_closeConnection(connection); + return -1; + } + + c->connection = connection; + + return 0; +} + + +int mpc_error(mpd_client_t *c) { if( c == NULL || c->connection == NULL ) @@ -139,11 +164,16 @@ mpc_update_playlist(mpd_client_t *c) // fprintf(stderr, "mpc_update_playlist(): status->playlist = %d\n", c->status->playlist); + if( mpc_error(c) ) + return -1; + if( c->playlist ) mpc_free_playlist(c); c->playlist_length=0; mpd_sendPlaylistInfoCommand(c->connection,-1); + if( mpc_error(c) ) + return -1; while( (entity=mpd_getNextInfoEntity(c->connection)) ) { if(entity->type==MPD_INFO_ENTITY_TYPE_SONG) @@ -218,18 +248,21 @@ mpc_get_song_name(mpd_Song *song) int mpc_update(mpd_client_t *c) { + if( mpc_error(c) ) + return -1; + if( c->status ) { mpd_freeStatus(c->status); } c->status = mpd_getStatus(c->connection); + if( mpc_error(c) ) + return -1; - // if( c->playlist == NULL || c->playlist_id!=c->status->playlist ) if( c->playlist_id!=c->status->playlist ) mpc_update_playlist(c); - // if( c->song == NULL || c->status->song != c->song_id ) if( c->status->song != c->song_id ) { c->song = mpc_playlist_get_song(c, c->status->song); @@ -278,6 +311,9 @@ mpc_update_filelist(mpd_client_t *c) { mpd_InfoEntity *entity; + if( mpc_error(c) ) + return -1; + if( c->filelist ) mpc_free_filelist(c); |