[Goodies-commits] r2462 - xfce4-mpc-plugin/trunk/panel-plugin

Landry Breuil landry at xfce.org
Sun Jan 28 16:24:23 CET 2007


Author: landry
Date: 2007-01-28 15:24:23 +0000 (Sun, 28 Jan 2007)
New Revision: 2462

Modified:
   xfce4-mpc-plugin/trunk/panel-plugin/simple-libmpd.c
   xfce4-mpc-plugin/trunk/panel-plugin/simple-libmpd.h
   xfce4-mpc-plugin/trunk/panel-plugin/xfce4-mpc-plugin.c
Log:
Fixed ugly crash introduced when removing O_NONBLOCK, and added a recv_buffer


Modified: xfce4-mpc-plugin/trunk/panel-plugin/simple-libmpd.c
===================================================================
--- xfce4-mpc-plugin/trunk/panel-plugin/simple-libmpd.c	2007-01-28 15:05:37 UTC (rev 2461)
+++ xfce4-mpc-plugin/trunk/panel-plugin/simple-libmpd.c	2007-01-28 15:24:23 UTC (rev 2462)
@@ -125,7 +125,7 @@
    FD_SET(mo->socket,&fds);
    if((err = select(mo->socket+1,&fds,NULL,NULL,&tv)) == 1)
    {
-      if ((nbread = recv(mo->socket, mo->buffer, MAXBUFLEN, 0)) < 0)
+      if ((nbread = recv(mo->socket, mo->recv_buffer, MAXBUFLEN, 0)) < 0)
       {
          mo->error = MPD_ERROR_NORESPONSE;
          DBG("ERROR @recv(), err=%s",strerror(errno));
@@ -138,6 +138,7 @@
           return;
       }
       mo->buflen = nbread;
+      strncpy(mo->buffer, mo->recv_buffer, mo->buflen);
       mo->buffer[mo->buflen] = '\0';
    }
    else if(err < 0)
@@ -195,7 +196,7 @@
    FD_SET(mo->socket,&fds);
    if((err = select(mo->socket+1,&fds,NULL,NULL,&tv)) == 1)
    {
-      if ((nbread = recv(mo->socket, mo->buffer, MAXBUFLEN, 0)) < 0)
+      if ((nbread = recv(mo->socket, mo->recv_buffer, MAXBUFLEN, 0)) < 0)
       {
          mo->error = MPD_ERROR_NORESPONSE;
          DBG("ERROR @recv(), err=%s",strerror(errno));
@@ -210,6 +211,7 @@
 
       DBG("Read %d bytes, buff=\"%s\"", nbread, mo->buffer);
       mo->buflen = nbread;
+      strncpy(mo->buffer, mo->recv_buffer, mo->buflen);
       mo->buffer[mo->buflen] = '\0';
    }
    else if(err < 0)
@@ -284,8 +286,8 @@
       DBG("Sent %d bytes",nbwri);
 
       nbread = mpd_wait_for_answer(mo);
-      /* special case for long answers with 'playlistinfo' */
-      while (nbread == MAXBUFLEN)
+      /* special case for long answers with 'playlistinfo' - hack to loop until we have received the final OK\n*/
+      while (nbread == MAXBUFLEN || 0 != strcmp(mo->buffer + strlen(mo->buffer) - 3,"OK\n"))
       {
          /* save the end of the buffer from last occurence of 'file:', and replace it with 'OK\n' */
          ptr = g_strrstr(mo->buffer, "file:");
@@ -376,7 +378,6 @@
    mpd_Song* ms = (mpd_Song*) param;
    char *eol,*ptr;
    char key[15], value[200];
-
    ms->artist = ms->album = ms->title = ms->track = NULL;
    ms->id = ms->pos = 0;
 

Modified: xfce4-mpc-plugin/trunk/panel-plugin/simple-libmpd.h
===================================================================
--- xfce4-mpc-plugin/trunk/panel-plugin/simple-libmpd.h	2007-01-28 15:05:37 UTC (rev 2461)
+++ xfce4-mpc-plugin/trunk/panel-plugin/simple-libmpd.h	2007-01-28 15:24:23 UTC (rev 2462)
@@ -64,6 +64,7 @@
    mpd_Song* cursong;
    int error;
    char buffer[MAXBUFLEN*2];
+   char recv_buffer[MAXBUFLEN];
    int buflen;
 } MpdObj;
 

Modified: xfce4-mpc-plugin/trunk/panel-plugin/xfce4-mpc-plugin.c
===================================================================
--- xfce4-mpc-plugin/trunk/panel-plugin/xfce4-mpc-plugin.c	2007-01-28 15:05:37 UTC (rev 2461)
+++ xfce4-mpc-plugin/trunk/panel-plugin/xfce4-mpc-plugin.c	2007-01-28 15:24:23 UTC (rev 2462)
@@ -398,7 +398,11 @@
    renderer = gtk_cell_renderer_text_new ();
    gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), -1, "Title", renderer, "text", 1, NULL);
 
-   mpc_plugin_reconnect(mpc);
+   if (!mpc_plugin_reconnect(mpc))
+   {
+      gtk_widget_destroy(mpc->playlist);
+      return;
+   }
 
    current = mpd_player_get_current_song_pos (mpc->mo);
    DBG ("Current song pos in the list: %d", current);




More information about the Goodies-commits mailing list