From: 13:29:00 Tim Janik Date: Thu, 6 Dec 2007 12:28:25 +0000 (+0000) Subject: detect non-blocking fd EOF by read()==0 following poll(), needed on MacOS. X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=8844df91017f79ccdd40fd38f621e3fae807847a;p=dana%2Fcg-glib.git detect non-blocking fd EOF by read()==0 following poll(), needed on MacOS. 2007-12-06 13:29:00 Tim Janik * glib/gtester.c (child_report_cb): detect non-blocking fd EOF by read()==0 following poll(), needed on MacOS. svn path=/trunk/; revision=6059 --- diff --git a/ChangeLog b/ChangeLog index bbc82f2a..533271a7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-12-06 13:29:00 Tim Janik + + * glib/gtester.c (child_report_cb): detect non-blocking fd EOF + by read()==0 following poll(), needed on MacOS. + 2007-12-06 Mathias Hasselmann * glib/gunidecomp.c: Mention g_utf8_normalize() diff --git a/glib/gtester.c b/glib/gtester.c index 499858fe..62337b72 100644 --- a/glib/gtester.c +++ b/glib/gtester.c @@ -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