? DEADJOE
? build/win32/vs8/Makefile
? build/win32/vs8/Makefile.in
? glib/DEADJOE
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/glib/ChangeLog,v
retrieving revision 1.2246
diff -p -u -r1.2246 ChangeLog
--- ChangeLog	19 Feb 2006 17:17:32 -0000	1.2246
+++ ChangeLog	21 Feb 2006 13:14:05 -0000
@@ -1,3 +1,11 @@
+2006-02-20  Benjamin Berg  <benjamin@sipsolutions.net>
+
+	* glib/giounix.c: (g_io_unix_check):
+	* glib/giowin32.c: (g_io_win32_check):
+	* glib/gmain.c: (g_main_context_check):
+	* glib/gmain.h:
+	Remove broken sources from the mainloop, to prevent a poll loop.
+
 2006-02-19  Martyn Russell  <martyn@imendio.com>
 	
 	* tests/asyncqueue-test.c: 
Index: glib/giounix.c
===================================================================
RCS file: /cvs/gnome/glib/glib/giounix.c,v
retrieving revision 1.31
diff -p -u -r1.31 giounix.c
--- glib/giounix.c	14 Mar 2005 04:26:57 -0000	1.31
+++ glib/giounix.c	21 Feb 2006 13:14:08 -0000
@@ -92,13 +92,13 @@ static GIOStatus	g_io_unix_set_flags	(GI
 						 GError      **err);
 static GIOFlags 	g_io_unix_get_flags	(GIOChannel   *channel);
 
-static gboolean g_io_unix_prepare  (GSource     *source,
-				    gint        *timeout);
-static gboolean g_io_unix_check    (GSource     *source);
-static gboolean g_io_unix_dispatch (GSource     *source,
-				    GSourceFunc  callback,
-				    gpointer     user_data);
-static void     g_io_unix_finalize (GSource     *source);
+static gboolean           g_io_unix_prepare  (GSource     *source,
+		                              gint        *timeout);
+static GSourceCheckResult g_io_unix_check    (GSource     *source);
+static gboolean           g_io_unix_dispatch (GSource     *source,
+				              GSourceFunc  callback,
+				              gpointer     user_data);
+static void               g_io_unix_finalize (GSource     *source);
 
 GSourceFuncs g_io_watch_funcs = {
   g_io_unix_prepare,
@@ -132,14 +132,20 @@ g_io_unix_prepare (GSource  *source,
   return ((watch->condition & buffer_condition) == watch->condition);
 }
 
-static gboolean 
+static GSourceCheckResult
 g_io_unix_check (GSource  *source)
 {
   GIOUnixWatch *watch = (GIOUnixWatch *)source;
   GIOCondition buffer_condition = g_io_channel_get_buffer_condition (watch->channel);
   GIOCondition poll_condition = watch->pollfd.revents;
 
-  return ((poll_condition | buffer_condition) & watch->condition);
+  if ((poll_condition | buffer_condition) & watch->condition)
+    return G_SOURCE_CHECK_READY;
+  else
+    if (poll_condition & (G_IO_ERR | G_IO_HUP | G_IO_NVAL))
+      return G_SOURCE_CHECK_FAULTED;
+
+  return G_SOURCE_CHECK_NOT_READY;
 }
 
 static gboolean
Index: glib/giowin32.c
===================================================================
RCS file: /cvs/gnome/glib/glib/giowin32.c,v
retrieving revision 1.66
diff -p -u -r1.66 giowin32.c
--- glib/giowin32.c	8 Nov 2005 08:46:57 -0000	1.66
+++ glib/giowin32.c	21 Feb 2006 13:14:10 -0000
@@ -644,7 +644,7 @@ g_io_win32_prepare (GSource *source,
   return ((watch->condition & buffer_condition) == watch->condition);
 }
 
-static gboolean
+static G_SOURCE_CHECK_RESULT
 g_io_win32_check (GSource *source)
 {
   MSG msg;
@@ -656,7 +656,7 @@ g_io_win32_check (GSource *source)
   switch (channel->type)
     {
     case G_IO_WIN32_WINDOWS_MESSAGES:
-      return (PeekMessage (&msg, channel->hwnd, 0, 0, PM_NOREMOVE));
+      return (PeekMessage (&msg, channel->hwnd, 0, 0, PM_NOREMOVE)) ? G_SOURCE_CHECK_READY : G_SOURCE_CHECK_NOT_READY;
 
     case G_IO_WIN32_FILE_DESC:
       if (channel->debug)
@@ -669,7 +669,8 @@ g_io_win32_check (GSource *source)
       
       watch->pollfd.revents = (watch->pollfd.events & channel->revents);
 
-      return ((watch->pollfd.revents | buffer_condition) & watch->condition);
+      /* what happens, if the cd is removed, should this be an error? */
+      return ((watch->pollfd.revents | buffer_condition) & watch->condition) ? G_SOURCE_CHECK_READY : G_SOURCE_CHECK_NOT_READY;
 
     case G_IO_WIN32_SOCKET:
       if (channel->last_events & FD_WRITE)
@@ -716,7 +717,12 @@ g_io_win32_check (GSource *source)
       if (!channel->write_would_have_blocked && (channel->event_mask & FD_WRITE))
 	watch->pollfd.revents |= G_IO_OUT; /* This sucks but... */
 
-      return ((watch->pollfd.revents | buffer_condition) & watch->condition);
+      if ((watch->pollfd.revents | buffer_condition) & watch->condition)
+        return G_SOURCE_CHECK_READY;
+      else
+        if (watch->pollfd.revents & G_IO_HUP)
+          return G_SOURCE_CHECK_FAULTED;
+      return G_SOURCE_CHECK_NOT_READY;
 
     default:
       g_assert_not_reached ();
Index: glib/gmain.c
===================================================================
RCS file: /cvs/gnome/glib/glib/gmain.c,v
retrieving revision 1.138
diff -p -u -r1.138 gmain.c
--- glib/gmain.c	5 Jan 2006 21:07:55 -0000	1.138
+++ glib/gmain.c	21 Feb 2006 13:14:16 -0000
@@ -2424,8 +2424,18 @@ g_main_context_check (GMainContext *cont
 	  LOCK_CONTEXT (context);
 	  context->in_check_or_prepare--;
 	  
-	  if (result)
-	    source->flags |= G_SOURCE_READY;
+	  switch (result) {
+	    case G_SOURCE_CHECK_READY:
+	      source->flags |= G_SOURCE_READY;
+	      break;
+            case G_SOURCE_CHECK_FAULTED:
+              /* spit out warning, and unref source */
+              g_warning ("Removing a broken source.\n");
+              UNLOCK_CONTEXT (context);
+              g_source_destroy (source);
+              LOCK_CONTEXT (context);
+              break;
+          }
 	}
 
       if (source->flags & G_SOURCE_READY)
Index: glib/gmain.h
===================================================================
RCS file: /cvs/gnome/glib/glib/gmain.h,v
retrieving revision 1.20
diff -p -u -r1.20 gmain.h
--- glib/gmain.h	3 Jan 2006 14:52:34 -0000	1.20
+++ glib/gmain.h	21 Feb 2006 13:14:17 -0000
@@ -71,15 +71,21 @@ struct _GSourceCallbackFuncs
 
 typedef void (*GSourceDummyMarshal) (void);
 
+typedef enum {
+  G_SOURCE_CHECK_NOT_READY = 0,
+  G_SOURCE_CHECK_READY,
+  G_SOURCE_CHECK_FAULTED,
+} GSourceCheckResult;
+      
 struct _GSourceFuncs
 {
-  gboolean (*prepare)  (GSource    *source,
-			gint       *timeout_);
-  gboolean (*check)    (GSource    *source);
-  gboolean (*dispatch) (GSource    *source,
-			GSourceFunc callback,
-			gpointer    user_data);
-  void     (*finalize) (GSource    *source); /* Can be NULL */
+  gboolean (*prepare)            (GSource    *source,
+			          gint       *timeout_);
+  gboolean (*check)              (GSource    *source);
+  GSourceCheckResult (*dispatch) (GSource    *source,
+                                  GSourceFunc callback,
+			          gpointer    user_data);
+  void     (*finalize)           (GSource    *source); /* Can be NULL */
 
   /* For use by g_source_set_closure */
   GSourceFunc     closure_callback;	   
