Index: libsoup/soup-socket.c
===================================================================
RCS file: /cvs/gnome/libsoup/libsoup/soup-socket.c,v
retrieving revision 1.61
diff -u -r1.61 soup-socket.c
--- libsoup/soup-socket.c	15 Aug 2005 11:25:04 -0000	1.61
+++ libsoup/soup-socket.c	20 Oct 2005 11:27:40 -0000
@@ -1001,8 +1001,12 @@
 	SoupSocket *sock = user_data;
 	SoupSocketPrivate *priv = SOUP_SOCKET_GET_PRIVATE (sock);
 
-	priv->read_tag = 0;
-	g_signal_emit (sock, signals[READABLE], 0);
+	if (cond & (G_IO_HUP | G_IO_ERR)) {
+		soup_socket_disconnect (sock);
+	} else {
+		priv->read_tag = 0;
+		g_signal_emit (sock, signals[READABLE], 0);
+	}
 
 	return FALSE;
 }
@@ -1041,7 +1045,8 @@
 
 		if (!priv->read_tag) {
 			priv->read_tag =
-				g_io_add_watch (priv->iochannel, cond,
+				g_io_add_watch (priv->iochannel, 
+						cond | G_IO_HUP | G_IO_ERR,
 						socket_read_watch, sock);
 		}
 		return SOUP_SOCKET_WOULD_BLOCK;
@@ -1199,8 +1204,12 @@
 	SoupSocket *sock = user_data;
 	SoupSocketPrivate *priv = SOUP_SOCKET_GET_PRIVATE (sock);
 
-	priv->write_tag = 0;
-	g_signal_emit (sock, signals[WRITABLE], 0);
+	if (condition & (G_IO_HUP | G_IO_ERR)) {
+		soup_socket_disconnect (sock);
+	} else {
+		priv->write_tag = 0;
+		g_signal_emit (sock, signals[WRITABLE], 0);
+	}
 
 	return FALSE;
 }
@@ -1284,7 +1293,7 @@
 	}
 
 	priv->write_tag =
-		g_io_add_watch (priv->iochannel, cond, 
+		g_io_add_watch (priv->iochannel, cond | G_IO_HUP | G_IO_ERR, 
 				socket_write_watch, sock);
 	g_mutex_unlock (priv->iolock);
 	return SOUP_SOCKET_WOULD_BLOCK;
