--- old/giowin32.c	Fri Feb 24 03:33:34 2006
+++ new/giowin32.c	Fri Feb 24 03:45:31 2006
@@ -110,6 +110,7 @@
   int last_events;
   int event;
   gboolean write_would_have_blocked;
+  gboolean has_been_closed;
 };
 
 #define LOCK(mutex) EnterCriticalSection (&mutex)
@@ -352,6 +353,7 @@
   channel->last_events = 0;
   channel->event = 0;
   channel->write_would_have_blocked = FALSE;
+  channel->has_benn_closed = FALSE;
   InitializeCriticalSection (&channel->mutex);
 }
 
@@ -645,7 +647,10 @@
       g_assert_not_reached ();
       abort ();
     }
-  return ((watch->condition & buffer_condition) == watch->condition);
+	
+  gboolean ret=((watch->condition & buffer_condition) == watch->condition);
+  ret |= channel->has_been_closed && (watch->condition & G_IO_HUP);
+  return ret;
 }
 
 static gboolean
@@ -715,7 +720,10 @@
 	watch->pollfd.revents |= G_IO_IN;
       if (channel->last_events & (FD_WRITE | FD_CONNECT))
 	watch->pollfd.revents |= G_IO_OUT;
-      if (watch->pollfd.revents == 0 && (channel->last_events & (FD_CLOSE)))
+	  /* prevent loss of the closed signal due to buffered reads */
+	  if (channel->last_events & FD_CLOSE)
+		  channel->has_been_closed=TRUE;
+      if (watch->pollfd.revents == 0 && channel->has_been_closed)
 	watch->pollfd.revents |= G_IO_HUP;
 
       if (!channel->write_would_have_blocked && (channel->event_mask & FD_WRITE))
