infopipe work in progress
authorPhilip Kovacs <pkovacs@users.sourceforge.net>
Thu, 5 Jan 2006 07:42:45 +0000 (07:42 +0000)
committerPhilip Kovacs <pkovacs@users.sourceforge.net>
Thu, 5 Jan 2006 07:42:45 +0000 (07:42 +0000)
git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky@464 7f574dfc-610e-0410-a909-a81674777703

src/infopipe.c

index 7e1b2ab..f4e821b 100644 (file)
@@ -90,28 +90,28 @@ void *infopipe_service(void *pvoid)
             FD_ZERO(&readset);
            FD_SET(fd,&readset);
 
-           /* This select() can block for a brief while (tm time value) and is 
-               ideally suited for a worker thread such as this. We don't want to 
-               slow down ui updates in the main thread as there is already excess 
-               latency there. */
-            if (select(fd+1,&readset,NULL,NULL,&tm) != 1) /* nothing to read yet */
-                break;
+           /* The select() below can block for a brief time (tm value) and is 
+               ideally suited for a worker thread such as this.  We don't want 
+               to slow down ui updates in the main thread as there is already 
+              excess latency there. */
+            if (select(fd+1,&readset,NULL,NULL,&tm) == 1) { /* something to read */
                    
-            if (read(fd,buf,sizeof(buf))>0) {
+                if (read(fd,buf,sizeof(buf)) > 0) { /* buf has data */
                    
-               pbuf=buf;
-               pthread_mutex_lock(&info.infopipe.item_mutex);
-               for (i=0;i<14;i++) {
-                    sscanf(pbuf,"%*[^:]: %[^\n]",g_item[i]);
-                   while(*pbuf++ != '\n');
-               }
-               pthread_mutex_unlock(&info.infopipe.item_mutex);
-
-                /* -- debug to console --
-               for(i=0;i<14;i++)
-                   printf("%s\n",g_item[i]);
-                */
-
+                   pbuf=buf;
+                   pthread_mutex_lock(&info.infopipe.item_mutex);
+                   for (i=0;i<14;i++) {
+                       /* 14 lines of key: value pairs presented in a known order */
+                        sscanf(pbuf,"%*[^:]: %[^\n]",g_item[i]);
+                       while(*pbuf++ != '\n');
+                   }
+                   pthread_mutex_unlock(&info.infopipe.item_mutex);
+
+                    /* -- debug to console --
+                   for(i=0;i<14;i++)
+                       printf("%s\n",g_item[i]);
+                    */
+               }
            }
 
            if (close(fd)<0)