From dd7f9c032208a101c65eefed1839b159a4f3eb55 Mon Sep 17 00:00:00 2001 From: Avuton Olrich Date: Sat, 30 Aug 2008 06:35:13 -0700 Subject: [PATCH] Update libmpdclient --- src/libmpdclient.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/libmpdclient.c b/src/libmpdclient.c index 81811a6..1c19dd8 100644 --- a/src/libmpdclient.c +++ b/src/libmpdclient.c @@ -100,18 +100,21 @@ static int do_connect_fail(mpd_Connection *connection, const struct sockaddr *serv_addr, int addrlen) { int iMode = 1; /* 0 = blocking, else non-blocking */ + if (connect(connection->sock, serv_addr, addrlen) == SOCKET_ERROR) + return 1; ioctlsocket(connection->sock, FIONBIO, (u_long FAR*) &iMode); - return (connect(connection->sock,serv_addr,addrlen) == SOCKET_ERROR - && WSAGetLastError() != WSAEWOULDBLOCK); + return 0; } #else /* !WIN32 (sane operating systems) */ static int do_connect_fail(mpd_Connection *connection, const struct sockaddr *serv_addr, int addrlen) { - int flags = fcntl(connection->sock, F_GETFL, 0); + int flags; + if (connect(connection->sock, serv_addr, addrlen) < 0) + return 1; + flags = fcntl(connection->sock, F_GETFL, 0); fcntl(connection->sock, F_SETFL, flags | O_NONBLOCK); - return (connect(connection->sock,serv_addr,addrlen)<0 && - errno!=EINPROGRESS); + return 0; } #endif /* !WIN32 */ @@ -129,7 +132,7 @@ static int mpd_connect(mpd_Connection * connection, const char * host, int port, * Setup hints */ hints.ai_flags = AI_ADDRCONFIG; - hints.ai_family = PF_UNSPEC; + hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; hints.ai_addrlen = 0; @@ -151,6 +154,8 @@ static int mpd_connect(mpd_Connection * connection, const char * host, int port, for (res = addrinfo; res; res = res->ai_next) { /* create socket */ + if (connection->sock >= 0) + closesocket(connection->sock); connection->sock = socket(res->ai_family, SOCK_STREAM, res->ai_protocol); if (connection->sock < 0) { @@ -167,11 +172,13 @@ static int mpd_connect(mpd_Connection * connection, const char * host, int port, /* connect stuff */ if (do_connect_fail(connection, res->ai_addr, res->ai_addrlen)) { - /* try the next address family */ + /* try the next address */ closesocket(connection->sock); connection->sock = -1; continue; } + + break; } freeaddrinfo(addrinfo); @@ -222,6 +229,8 @@ static int mpd_connect(mpd_Connection * connection, const char * host, int port, break; } + if (connection->sock >= 0) + closesocket(connection->sock); if((connection->sock = socket(dest->sa_family,SOCK_STREAM,0))<0) { strcpy(connection->errorStr,"problems creating socket"); connection->error = MPD_ERROR_SYSTEM; @@ -347,6 +356,7 @@ mpd_Connection * mpd_newConnection(const char * host, int port, float timeout) { struct timeval tv; fd_set fds; strcpy(connection->buffer,""); + connection->sock = -1; connection->buflen = 0; connection->bufstart = 0; strcpy(connection->errorStr,""); @@ -939,6 +949,7 @@ static void mpd_finishSong(mpd_Song * song) { if(song->date) free(song->date); if(song->genre) free(song->genre); if(song->composer) free(song->composer); + if(song->performer) free(song->performer); if(song->disc) free(song->disc); if(song->comment) free(song->comment); } @@ -968,6 +979,7 @@ mpd_Song * mpd_songDup(mpd_Song * song) { if(song->date) ret->date = strdup(song->date); if(song->genre) ret->genre= strdup(song->genre); if(song->composer) ret->composer= strdup(song->composer); + if(song->performer) ret->performer = strdup(song->performer); if(song->disc) ret->disc = strdup(song->disc); if(song->comment) ret->comment = strdup(song->comment); ret->time = song->time; -- 2.11.4.GIT