socket handling patch for glib-win32



Tor,

We ran into an issue getting the loudmouth XMPP library ported to win32. 
As far as we could see, GLib was tearing the socket's io_channel after 
the first watch completes, preventing the installation of the remaining 
watches and proper handling of stream events in the event loop.

Attached is a patch that just comments out the tear-down, which made 
things work for us. I've no idea what the teardown code is supposed
to be doing though, so please review and and let us know if there's
a cleaner solution. Either way, we'd like to get the issue resolved
upstream.

The patch is against the 2.4.7 win32 source release from 
http://www.gimp.org/~tml/gimp/win32/ It also contains some
build tweaks and warning fixes; the important bit is the
change to giowin32.c


There's also a larger issue I'd like to mention. I talked to Owen
a bit about this on irc, but would like to bring it up here as well.
It seems (to us at least) that GLib would really benefit from a
socket abstraction api. The support for setting up an io_channel
and calling handlers from the event loop is really nice, and a
compelling argument for using GLib, but until MS Windows starts
supporting the BSD socket API, anyone doing cross-platform network 
programming has to write their own little abstraction, as we did
for loudmouth. Having that abstraction available in GLib itself
would both save a lot of work, and increase the portability of
network-aware applications.

FWIW,
 -r

Index: glib/gatomic.c
===================================================================
--- glib/gatomic.c	(.../tags/glib-win32/glib-2.4.7)	(revision 181)
+++ glib/gatomic.c	(.../trunk/code/glib)	(working copy)
@@ -472,9 +472,9 @@
 				   gint32    oldval, 
 				   gint32    newval)
 {
-  return (guint32)InterlockedCompareExchange ((PVOID*)atomic, 
-                                              (PVOID)newval, 
-                                              (PVOID)oldval) == oldval;
+  return (guint32)InterlockedCompareExchange ((LONG*)atomic,
+                                              (LONG)newval,
+                                              (LONG)oldval) == oldval;
 }
 
 gboolean 
@@ -485,7 +485,9 @@
 # if GLIB_SIZEOF_VOID_P != 4 /* no 32-bit system */
 #  error "InterlockedCompareExchangePointer needed"
 # else
-   return InterlockedCompareExchange (atomic, newval, oldval) == oldval;
+   return (gpointer)InterlockedCompareExchange ((LONG *)atomic, 
+                                     (LONG)newval,
+                                     (LONG)oldval) == oldval;
 # endif
 }
 #endif /* DEFINE_WITH_WIN32_INTERLOCKED */
Index: glib/giowin32.c
===================================================================
--- glib/giowin32.c	(.../tags/glib-win32/glib-2.4.7)	(revision 181)
+++ glib/giowin32.c	(.../trunk/code/glib)	(working copy)
@@ -727,13 +727,15 @@
   channel->watches = g_slist_remove (channel->watches, watch);
 
   SetEvent (channel->data_avail_noticed_event);
-  if (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);
-  }
+// JAM --- Don't delete the channel for no reason.  I'm unsure if this is correct though,
+// but it seems to fix the bug.
+//  if (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);
+//  }*/
 
   g_io_channel_unref (watch->channel);
   UNLOCK (channel->mutex);
Index: gobject/makefile.msc
===================================================================
--- gobject/makefile.msc	(.../tags/glib-win32/glib-2.4.7)	(revision 181)
+++ gobject/makefile.msc	(.../trunk/code/glib)	(working copy)
@@ -21,8 +21,8 @@
 	gobject-query.exe \
 	libgobject-2.0-0.dll	\
 	gobject-2.4s.lib \
-	testgobject.exe	\
-	testoverride.exe
+	testgobject.exe
+#	testoverride.exe
 
 gobject_OBJECTS =		\
 	gboxed.obj		\
Index: build/win32/dirent/makefile.msc
===================================================================
--- build/win32/dirent/makefile.msc	(.../tags/glib-win32/glib-2.4.7)	(revision 181)
+++ build/win32/dirent/makefile.msc	(.../trunk/code/glib)	(working copy)
@@ -4,7 +4,7 @@
 
 dirent_OBJECTS = dirent.obj
 
-INCLUDES = -I.
+INCLUDES = -I.  -I $(TOP)\glib
 
 all : dirent.lib
 
Index: build/win32/make.msc
===================================================================
--- build/win32/make.msc	(.../tags/glib-win32/glib-2.4.7)	(revision 181)
+++ build/win32/make.msc	(.../trunk/code/glib)	(working copy)
@@ -75,8 +75,8 @@
 GTKGLAREA_CFLAGS = -I $(GTKGLAREA)
 GTKGLAREA_LIBS = $(GTKGLAREA)\gtkgl\gtkgl-$(GTKGLAREA_VER).lib
 
-INTL_CFLAGS = -I $(INTL)
-INTL_LIBS = $(INTL)\intl.lib 
+INTL_CFLAGS = -I $(INTL)\include
+INTL_LIBS = $(INTL)\lib\intl.lib
 
 LIBICONV_CFLAGS = -I $(LIBICONV)\include
 LIBICONV_LIBS = $(LIBICONV)\lib\iconv.lib


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