Index: glib/giowin32.c
===================================================================
--- glib/giowin32.c	(revision 7370)
+++ glib/giowin32.c	(working copy)
@@ -116,6 +116,7 @@
   int last_events;
   HANDLE event;
   gboolean write_would_have_blocked;
+  gboolean ever_writable;
 };
 
 #define LOCK(mutex) EnterCriticalSection (&mutex)
@@ -242,6 +243,7 @@
   channel->last_events = 0;
   channel->event = NULL;
   channel->write_would_have_blocked = FALSE;
+  channel->ever_writable = FALSE;
   InitializeCriticalSection (&channel->mutex);
 }
 
@@ -734,7 +736,9 @@
 	    g_print ("\n  setting last_events=0");
 	  channel->last_events = 0;
 
-	  if ((event_mask & FD_WRITE) && !channel->write_would_have_blocked)
+	  if ((event_mask & FD_WRITE) &&
+	      channel->ever_writable &&
+	      !channel->write_would_have_blocked)
 	    {
 	      if (channel->debug)
 		g_print (" WSASetEvent(%p)", (WSAEVENT) watch->pollfd.fd);
@@ -845,11 +849,15 @@
 			 (HANDLE) watch->pollfd.fd);
 	      ResetEvent ((HANDLE) watch->pollfd.fd);
 	    }
+	  else if (events.lNetworkEvents & FD_WRITE)
+	    channel->ever_writable = TRUE;
 	  channel->last_events = events.lNetworkEvents;
 	}
+
       watch->pollfd.revents = 0;
       if (channel->last_events & (FD_READ | FD_ACCEPT))
 	watch->pollfd.revents |= G_IO_IN;
+
       if (channel->last_events & FD_WRITE)
 	watch->pollfd.revents |= G_IO_OUT;
       else
@@ -869,10 +877,12 @@
 	}
 
       /* Regardless of WSAEnumNetworkEvents() result, if watching for
-       * writability, unless last write would have blocked set
-       * G_IO_OUT. But never set both G_IO_OUT and G_IO_HUP.
+       * writability, and if we have ever got a FD_WRITE event, and
+       * unless last write would have blocked, set G_IO_OUT. But never
+       * set both G_IO_OUT and G_IO_HUP.
        */
       if (!(watch->pollfd.revents & G_IO_HUP) &&
+	  channel->ever_writable &&
 	  !channel->write_would_have_blocked &&
 	  (channel->event_mask & FD_WRITE))
 	watch->pollfd.revents |= G_IO_OUT;
