[gnet] patch for win32 issues



The following gnet examples don't work under Win32:
echoclient-gconn, echoserver-gserver and echoserver-async.
 
I finally identified the problem as follow:
When you remove an io watch on a socket, all the other io watches on
this socket (old ones and even new ones) don't work any more, they will
never be called again.

It's a glib bug which results from a patch for another bug
(http://bugzilla.gnome.org/show_bug.cgi?id=147392)
Here's a proposed glib v2.4.7 patch (I just submitted it to bugzilla).

David Ergo
Alterface
--- glib/giowin32.c	Wed Jun  8 13:57:40 2005
+++ glib/giowin32.c.patched	Thu Jun  9 07:54:26 2005
@@ -596,6 +596,12 @@
     g_print ("select_thread %#x: got error, setting data_avail\n",
 	     channel->thread_id);
   SetEvent (channel->data_avail_event);
+
+  /* Resetting channel fields */
+  channel->needs_close = FALSE;
+  channel->revents = 0;
+  channel->thread_id = 0;
+
   g_io_channel_unref ((GIOChannel *)channel);
   UNLOCK (channel->mutex);
 
@@ -727,12 +733,18 @@
   channel->watches = g_slist_remove (channel->watches, watch);
 
   SetEvent (channel->data_avail_noticed_event);
-  if (channel->type == G_IO_WIN32_SOCKET)
+  if (channel->watches == NULL && channel->type == G_IO_WIN32_SOCKET)
   {
     /* Tell select_thread() to exit */
     channel->needs_close = 1;
     /* Wake up select_thread() from its blocking select() */
     send (channel->reset_send, send_buffer, sizeof (send_buffer), 0);
+    /* Wait for select_thread() to terminate */
+    do {
+      UNLOCK (channel->mutex);
+      Sleep(10);  /* sleep 10 ms */
+      LOCK (channel->mutex);
+    } while (channel->thread_id != 0);  
   }
 
   g_io_channel_unref (watch->channel);


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