Merge branch 'master' of kenny.imendio.com:/var/git/public/projects/loudmouth into loudmouth-1-2
authorMikael Hallendal <micke@imendio.com>
Mon, 12 Feb 2007 16:24:59 +0100
changeset 201 0c24c0f86c17
parent 198 6c7c4034896b (current diff)
parent 200 7dc7f9b09317 (diff)
child 203 251f305e80fb
Merge branch 'master' of kenny.imendio.com:/var/git/public/projects/loudmouth into loudmouth-1-2
--- a/loudmouth/lm-connection.c	Fri Feb 02 15:20:28 2007 +0100
+++ b/loudmouth/lm-connection.c	Mon Feb 12 16:24:59 2007 +0100
@@ -1072,29 +1072,27 @@
 }
 
 static gboolean
-connection_in_event (GIOChannel   *source,
-		     GIOCondition  condition,
-		     LmConnection *connection)
+connection_read_incoming (LmConnection *connection,
+			  gchar        *buf,
+			  gsize         buf_size,
+			  gsize        *bytes_read,
+			  gboolean     *hangup)
 {
-	gchar     buf[IN_BUFFER_SIZE];
-	gsize     bytes_read;
 	GIOStatus status;
-       
-	if (!connection->io_channel) {
-		return FALSE;
-	}
+
+	*hangup = FALSE;
 
 	if (connection->ssl) {
 		status = _lm_ssl_read (connection->ssl, 
-				       buf, IN_BUFFER_SIZE - 1, &bytes_read);
+				       buf, buf_size - 1, bytes_read);
 	} else {
 		status = g_io_channel_read_chars (connection->io_channel,
-						  buf, IN_BUFFER_SIZE - 1,
-						  &bytes_read,
+						  buf, buf_size - 1,
+						  bytes_read,
 						  NULL);
 	}
 
-	if (status != G_IO_STATUS_NORMAL || bytes_read < 0) {
+	if (status != G_IO_STATUS_NORMAL || *bytes_read < 0) {
 		gint reason;
 		
 		switch (status) {
@@ -1102,7 +1100,8 @@
 			reason = LM_DISCONNECT_REASON_HUP;
 			break;
 		case G_IO_STATUS_AGAIN:
-			return TRUE;
+			/* No data readable but we didn't hangup */
+			return FALSE;
 			break;
 		case G_IO_STATUS_ERROR:
 			reason = LM_DISCONNECT_REASON_ERROR;
@@ -1113,23 +1112,47 @@
 
 		connection_do_close (connection);
 		connection_signal_disconnect (connection, reason);
+
+		/* Notify connection_in_event that we hangup the connection */
+		*hangup = TRUE;
 		
 		return FALSE;
 	}
 
-	buf[bytes_read] = '\0';
-	g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, "\nRECV [%d]:\n", 
-	       (int)bytes_read);
-	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, 
-	       "-----------------------------------\n");
+	buf[*bytes_read] = '\0';
+
+	/* There is more data to be read */
+	return TRUE;
+}
+
+static gboolean
+connection_in_event (GIOChannel   *source,
+		     GIOCondition  condition,
+		     LmConnection *connection)
+{
+	gchar    buf[IN_BUFFER_SIZE];
+	gsize    bytes_read;
+	gboolean hangup;
 
-	lm_verbose ("Read: %d chars\n", (int)bytes_read);
+	while (connection_read_incoming (connection, buf, IN_BUFFER_SIZE,
+					 &bytes_read, &hangup)) {
+		g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, "\nRECV [%d]:\n", 
+		       (int)bytes_read);
+		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, 
+		       "-----------------------------------\n");
 
-	lm_parser_parse (connection->parser, buf);
-	
+		lm_verbose ("Read: %d chars\n", (int)bytes_read);
+
+		lm_parser_parse (connection->parser, buf);
+	}
+
+	if (hangup) {
+		return FALSE;
+	}
+
 	return TRUE;
 }