[maemo-commits] [maemo-commits] r8357 - projects/haf/trunk/osso-af-utils/src

From: www-data at stage.maemo.org www-data at stage.maemo.org
Date: Mon Nov 27 17:07:14 EET 2006
Author: kihamala
Date: 2006-11-27 17:07:13 +0200 (Mon, 27 Nov 2006)
New Revision: 8357

Modified:
   projects/haf/trunk/osso-af-utils/src/play-sound.c
Log:
added delay to avoid possible tight loop


Modified: projects/haf/trunk/osso-af-utils/src/play-sound.c
===================================================================
--- projects/haf/trunk/osso-af-utils/src/play-sound.c	2006-11-27 13:51:28 UTC (rev 8356)
+++ projects/haf/trunk/osso-af-utils/src/play-sound.c	2006-11-27 15:07:13 UTC (rev 8357)
@@ -153,6 +153,9 @@
             buf = malloc (available_bytes) ;
             while (TRUE)
             {
+                struct timeval tv;
+                int first_time = 1;
+                
                 ioctl (monitor_fd, FIONREAD, &available_bytes) ;
                 if (available_bytes > max_avail)
                 {
@@ -160,9 +163,21 @@
 					max_avail = available_bytes ;
                 }
                 read_return = read (monitor_fd, &buf, available_bytes) ;
-                if (read_return <= 0) break ;
+                if (read_return < 0)
+                {
+                    break ;
+                }
+                else if (read_return == 0 && !first_time)
+                {
+                    break ;
+                }
+
+                tv.tv_sec = 0;
+                tv.tv_usec = 200000;
+                select (0, NULL, NULL, NULL, &tv); /* avoid tight loop */
+                first_time = 0;
             }
-			free (buf) ;
+            free (buf) ;
             close (monitor_fd) ;
         }
         esd_free_server_info (esd_server_info) ;


More information about the maemo-commits mailing list