[glib/glib-2-34] Fix pollable streams for Darwin (and probably BSD)



commit 30bb8e187aaf509b97b3508546e8a1ca3ecc8a7a
Author: John Ralls <jralls ceridwen us>
Date:   Fri Nov 9 09:22:19 2012 -0800

    Fix pollable streams for Darwin (and probably BSD)
    
    Darwin's poll doesn't change revents if there are no available events, though it returns 0. Initialize the fd.revents to 0 so that the test passes.
    
    That reveals a test failure, though, because with socket streams it takes time for an event to pass through the socket. Provide an 80-usec delay to allow time for the propagation.

 gio/gsocket.c                |    1 +
 gio/gunixinputstream.c       |    1 +
 gio/gunixoutputstream.c      |    1 +
 gio/tests/converter-stream.c |    6 ++++++
 gio/tests/pollable.c         |    3 +++
 5 files changed, 12 insertions(+), 0 deletions(-)
---
diff --git a/gio/gsocket.c b/gio/gsocket.c
index fffd304..13dff46 100644
--- a/gio/gsocket.c
+++ b/gio/gsocket.c
@@ -3388,6 +3388,7 @@ g_socket_condition_check (GSocket      *socket,
     gint result;
     poll_fd.fd = socket->priv->fd;
     poll_fd.events = condition;
+    poll_fd.revents = 0;
 
     do
       result = g_poll (&poll_fd, 1, 0);
diff --git a/gio/gunixinputstream.c b/gio/gunixinputstream.c
index a1639f6..b2c4e3f 100644
--- a/gio/gunixinputstream.c
+++ b/gio/gunixinputstream.c
@@ -577,6 +577,7 @@ g_unix_input_stream_pollable_is_readable (GPollableInputStream *stream)
 
   poll_fd.fd = unix_stream->priv->fd;
   poll_fd.events = G_IO_IN;
+  poll_fd.revents = 0;
 
   do
     result = g_poll (&poll_fd, 1, 0);
diff --git a/gio/gunixoutputstream.c b/gio/gunixoutputstream.c
index 4e00dcb..61ba683 100644
--- a/gio/gunixoutputstream.c
+++ b/gio/gunixoutputstream.c
@@ -532,6 +532,7 @@ g_unix_output_stream_pollable_is_writable (GPollableOutputStream *stream)
 
   poll_fd.fd = unix_stream->priv->fd;
   poll_fd.events = G_IO_OUT;
+  poll_fd.revents = 0;
 
   do
     result = g_poll (&poll_fd, 1, 0);
diff --git a/gio/tests/converter-stream.c b/gio/tests/converter-stream.c
index fc9c896..28c780a 100644
--- a/gio/tests/converter-stream.c
+++ b/gio/tests/converter-stream.c
@@ -1016,6 +1016,12 @@ test_converter_pollable (void)
 	  socket_out = NULL;
 	}
 
+      /* Wait a few ticks to check for the pipe to propagate the
+       * write. Finesses the race condition in the following test,
+       * where is_readable fails because the write hasn't propagated,
+       * but the read then succeeds because it has. */
+      g_usleep (80L);
+
       is_readable = g_pollable_input_stream_is_readable (pollable_in);
       res = g_pollable_input_stream_read_nonblocking (pollable_in,
 						      inptr, 1,
diff --git a/gio/tests/pollable.c b/gio/tests/pollable.c
index 8a27da8..b975fa1 100644
--- a/gio/tests/pollable.c
+++ b/gio/tests/pollable.c
@@ -70,6 +70,9 @@ write_callback (gpointer user_data)
   nwrote = g_output_stream_write (out, buf, 2, NULL, &error);
   g_assert_no_error (error);
   g_assert_cmpint (nwrote, ==, 2);
+/* Give the pipe a few ticks to propagate the write for sockets. On my
+ * iMac i7, 40 works, 30 doesn't. */
+  g_usleep (80L);
 
   check_source_readability_callback (GINT_TO_POINTER (TRUE));
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]