From 6c0042b0c87fe601b9ad606d4ee44305fc36d2cb Mon Sep 17 00:00:00 2001 From: Kalle Wallin Date: Sat, 20 Mar 2004 08:46:30 +0000 Subject: [PATCH] Added function mpc_reconnect(). git-svn-id: https://svn.musicpd.org/ncmpc/trunk@323 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- mpc.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/mpc.c b/mpc.c index f62d978..0b12e27 100644 --- a/mpc.c +++ b/mpc.c @@ -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; @@ -83,6 +88,26 @@ mpc_connect(char *host, int port) return c; } +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) { @@ -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); -- 2.30.2