2003-08-04 Mikael Hallendal <micke@imendio.com>
authorhallski <hallski>
Mon, 04 Aug 2003 21:18:23 +0000
changeset 28 8784d9121214
parent 27 763a2b67fa10
child 29 06a0e0c2e2eb
2003-08-04 Mikael Hallendal <micke@imendio.com> * loudmouth/lm-connection.c: (connection_in_event): - Disconnect and report that we are disconnected if read doesn't work. This solved the problem when Gossip eats 100% CPU because the server got disconnected. Fixes LM-9.
ChangeLog
loudmouth/lm-connection.c
--- a/ChangeLog	Mon Aug 04 20:49:29 2003 +0000
+++ b/ChangeLog	Mon Aug 04 21:18:23 2003 +0000
@@ -1,9 +1,12 @@
 2003-08-04  Mikael Hallendal  <micke@imendio.com>
 
+	* loudmouth/lm-connection.c: (connection_in_event): 
+	- Disconnect and report that we are disconnected if read doesn't work.
+	  This solved the problem when Gossip eats 100% CPU because the server
+	  got disconnected. Fixes LM-9.
+
 	* loudmouth/Makefile.am: Use -DRUNTIME_ENDIAN, fixes LM-8, bug #118502.
 
-2003-08-04  Mikael Hallendal  <micke@imendio.com>
-
 	* loudmouth/lm-connection.c: 
 	- Modifed patch from Mikhail Zabaluev, fixes LM-5.
 	* (connection_free): close connection if it's still open.
@@ -12,8 +15,6 @@
 	* (connection_in_event, connection_error_event, connection_hup_event):
 	- Return FALSE if io_channel = NULL.
 
-2003-08-04  Mikael Hallendal  <micke@imendio.com>
-
 	* configure.in:
 	- Submitted patch for Loudmouth from Mikhail Zabaluev to
 	  make configure.in use the aclocal-stuff from gnutls instead of
--- a/loudmouth/lm-connection.c	Mon Aug 04 20:49:29 2003 +0000
+++ b/loudmouth/lm-connection.c	Mon Aug 04 21:18:23 2003 +0000
@@ -373,8 +373,9 @@
 		     GIOCondition  condition,
 		     LmConnection *connection)
 {
-	gchar             buf[IN_BUFFER_SIZE];
-	gsize             bytes_read;
+	gchar     buf[IN_BUFFER_SIZE];
+	gsize     bytes_read;
+	GIOStatus status;
        
 	if (!connection->io_channel) {
 		return FALSE;
@@ -385,28 +386,59 @@
 		bytes_read = gnutls_record_recv (connection->gnutls_session,
 						 buf,IN_BUFFER_SIZE - 1);
 		if (bytes_read <= 0) {
-			connection_error_event (connection->io_channel, 
-						G_IO_HUP,
-						connection);
+			status = G_IO_STATUS_ERROR;
+			
+			//connection_error_event (connection->io_channel, 
+			//			G_IO_HUP,
+			//			connection);
+		}
+		else {
+			status = G_IO_STATUS_NORMAL;
 		}
 	} else {
 #endif
-	    g_io_channel_read_chars (connection->io_channel,
-				     buf, IN_BUFFER_SIZE - 1,
-				     &bytes_read,
-				     NULL);
+	    status = g_io_channel_read_chars (connection->io_channel,
+					      buf, IN_BUFFER_SIZE - 1,
+					      &bytes_read,
+					      NULL);
 #ifdef HAVE_GNUTLS
 	}
 #endif
 
+	if (status != G_IO_STATUS_NORMAL) {
+		gint reason;
+		
+		
+		switch (status) {
+		case G_IO_STATUS_EOF:
+			reason = LM_DISCONNECT_REASON_HUP;
+			break;
+		case G_IO_STATUS_AGAIN:
+			return TRUE;
+			break;
+		case G_IO_STATUS_ERROR:
+			reason = LM_DISCONNECT_REASON_ERROR;
+			break;
+		default:
+			reason = LM_DISCONNECT_REASON_UNKNOWN;
+		}
+
+		connection_do_close (connection);
+		connection_signal_disconnect (connection, reason);
+		
+		return FALSE;
+	}
+
 	buf[bytes_read] = '\0';
 	g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, "\nRECV:\n");
 	g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, 
 	       "-----------------------------------\n");
-	g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, "%s\n", buf);
+	g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, "'%s'\n", buf);
 	g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, 
 	       "-----------------------------------\n");
-	
+
+	lm_verbose ("Read: %d chars\n", bytes_read);
+
 	lm_parser_parse (connection->parser, buf);
 	
 	return TRUE;