detect non-blocking fd EOF by read()==0 following poll(), needed on MacOS.
author13:29:00 Tim Janik <timj@imendio.com>
Thu, 6 Dec 2007 12:28:25 +0000 (12:28 +0000)
committerTim Janik <timj@src.gnome.org>
Thu, 6 Dec 2007 12:28:25 +0000 (12:28 +0000)
2007-12-06 13:29:00  Tim Janik  <timj@imendio.com>

        * glib/gtester.c (child_report_cb): detect non-blocking fd EOF
        by read()==0 following poll(), needed on MacOS.

svn path=/trunk/; revision=6059

ChangeLog
glib/gtester.c

index bbc82f2aa90cc8820c9a4398b89ee157875f1a85..533271a7e58cebef0c2c71d9345c024496553e30 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-12-06 13:29:00  Tim Janik  <timj@imendio.com>
+
+       * glib/gtester.c (child_report_cb): detect non-blocking fd EOF
+       by read()==0 following poll(), needed on MacOS.
+
 2007-12-06  Mathias Hasselmann  <mathias@openismus.com>
 
        * glib/gunidecomp.c: Mention g_utf8_normalize()
index 499858fe838eb369f0f6d84d1fce8fd19dea1bdd..62337b7244267c11f181bf01a3a107646771e5cc 100644 (file)
@@ -184,12 +184,21 @@ child_report_cb (GIOChannel  *source,
 {
   GTestLogBuffer *tlb = data;
   GIOStatus status = G_IO_STATUS_NORMAL;
+  gboolean first_read_eof = FALSE, first_read = TRUE;
   gsize length = 0;
   do
     {
       guint8 buffer[READ_BUFFER_SIZE];
       GError *error = NULL;
       status = g_io_channel_read_chars (source, (gchar*) buffer, sizeof (buffer), &length, &error);
+      if (first_read && (condition & G_IO_IN))
+        {
+          /* on some unixes (MacOS) we need to detect non-blocking fd EOF
+           * by an IO_IN select/poll followed by read()==0.
+           */
+          first_read_eof = length == 0;
+        }
+      first_read = FALSE;
       if (length)
         {
           GTestLogMsg *msg;
@@ -206,11 +215,11 @@ child_report_cb (GIOChannel  *source,
           while (msg);
         }
       g_clear_error (&error);
-      /* ignore the io channel status, which seems to be bogus especially for non blocking fds */
+      /* ignore the io channel status, which will report intermediate EOFs for non blocking fds */
       (void) status;
     }
   while (length > 0);
-  if (condition & (G_IO_ERR | G_IO_HUP))
+  if (first_read_eof || (condition & (G_IO_ERR | G_IO_HUP)))
     {
       /* if there's no data to read and select() reports an error or hangup,
        * the fd must have been closed remotely