Make blocking reads work
authorSenko Rasic <senko.rasic@collabora.co.uk>
Sun, 09 Dec 2007 16:21:46 +0100
changeset 322 9d591fb31bc2
parent 321 d9dc997db56b
child 323 64ea88f05696
Make blocking reads work
loudmouth/lm-socket.c
--- a/loudmouth/lm-socket.c	Sun Dec 09 15:10:12 2007 +0100
+++ b/loudmouth/lm-socket.c	Sun Dec 09 16:21:46 2007 +0100
@@ -219,16 +219,16 @@
 		     LmSocket     *socket)
 {
 	gchar     buf[IN_BUFFER_SIZE];
-	gsize     bytes_read;
+	gsize     bytes_read = 0;
 	gboolean  read_anything = FALSE;
-	gboolean  hangup;
-	gint      reason;
+	gboolean  hangup = 0;
+	gint      reason = 0;
 
 	if (!socket->io_channel) {
 		return FALSE;
 	}
 
-	while (socket_read_incoming (socket, buf, IN_BUFFER_SIZE, 
+	while ((condition & G_IO_IN) && socket_read_incoming (socket, buf, IN_BUFFER_SIZE, 
 				     &bytes_read, &hangup, &reason)) {
 		
 		g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, "\nRECV [%d]:\n", 
@@ -244,6 +244,8 @@
 		(socket->data_func) (socket, buf, socket->user_data);
 
 		read_anything = TRUE;
+
+		condition = g_io_channel_get_buffer_condition (socket->io_channel);
 	}
 
 	/* If we have read something, delay the hangup so that the data can be