2003-08-04 Mikael Hallendal <micke@imendio.com>
authorhallski <hallski>
Mon, 04 Aug 2003 20:30:05 +0000
changeset 26 5dd8b6da1454
parent 25 489e48440773
child 27 763a2b67fa10
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. * (connection_do_open): Store away the GSource handlers. * (connection_do_close): Remove the GSources from the IOChannel. * (connection_in_event, connection_error_event, connection_hup_event): - Return FALSE if io_channel = NULL.
ChangeLog
loudmouth/lm-connection.c
--- a/ChangeLog	Mon Aug 04 20:14:48 2003 +0000
+++ b/ChangeLog	Mon Aug 04 20:30:05 2003 +0000
@@ -1,3 +1,13 @@
+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.
+	* (connection_do_open): Store away the GSource handlers.
+	* (connection_do_close): Remove the GSources from the IOChannel.
+	* (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:
--- a/loudmouth/lm-connection.c	Mon Aug 04 20:14:48 2003 +0000
+++ b/loudmouth/lm-connection.c	Mon Aug 04 20:30:05 2003 +0000
@@ -79,6 +79,9 @@
 
 	/* Communication */
 	GIOChannel *io_channel;
+	guint       io_watch_in;
+	guint       io_watch_err;
+	guint       io_watch_hup;
 
 	LmCallback *open_cb;
 	LmCallback *close_cb;
@@ -170,7 +173,7 @@
 	g_free (connection->server);
 
 	if (connection->io_channel) {
-		g_io_channel_unref (connection->io_channel);
+		connection_do_close (connection);
 	}
 
 	g_free (connection);
@@ -313,18 +316,18 @@
 	g_io_channel_set_buffered (connection->io_channel, FALSE);
 	g_io_channel_set_flags (connection->io_channel,
 				G_IO_FLAG_NONBLOCK, NULL);
-	g_io_add_watch (connection->io_channel,
-			G_IO_IN,
-			(GIOFunc) connection_in_event,
-			connection);
-	g_io_add_watch (connection->io_channel, 
-			G_IO_ERR,
-			(GIOFunc) connection_error_event,
-			connection);
-	g_io_add_watch (connection->io_channel,
-			G_IO_HUP,
-			(GIOFunc) connection_hup_event,
-			connection);
+	connection->io_watch_in = g_io_add_watch (connection->io_channel,
+						  G_IO_IN,
+						  (GIOFunc) connection_in_event,
+						  connection);
+	connection->io_watch_err = g_io_add_watch (connection->io_channel, 
+						   G_IO_ERR,
+						   (GIOFunc) connection_error_event,
+						   connection);
+	connection->io_watch_hup = g_io_add_watch (connection->io_channel,
+						   G_IO_HUP,
+						   (GIOFunc) connection_hup_event,
+						   connection);
 
 	connection->is_open = TRUE;
 
@@ -341,10 +344,18 @@
 connection_do_close (LmConnection *connection)
 {
 	if (connection->io_channel) {
+		g_source_remove (connection->io_watch_in);
+		g_source_remove (connection->io_watch_err);
+		g_source_remove (connection->io_watch_hup);
+
 		g_io_channel_unref (connection->io_channel);
+		connection->io_channel = NULL;
+	} 
+
+	if (!connection->is_open) {
+		return;
 	}
 
-	connection->io_channel = NULL;
 	connection->is_open = FALSE;
 
 #ifdef HAVE_GNUTLS
@@ -368,6 +379,7 @@
 	if (!connection->io_channel) {
 		return FALSE;
 	}
+
 #ifdef HAVE_GNUTLS
 	if (connection->use_ssl) {
 		bytes_read = gnutls_record_recv (connection->gnutls_session,
@@ -405,6 +417,10 @@
 			GIOCondition  condition,
 			LmConnection *connection)
 {
+	if (!connection->io_channel) {
+		return FALSE;
+	}
+
 	lm_verbose ("Error event: %d\n", condition);
 	
 	connection_do_close (connection);
@@ -418,6 +434,10 @@
 		      GIOCondition  condition,
 		      LmConnection *connection)
 {
+	if (!connection->io_channel) {
+		return FALSE;
+	}
+
 	lm_verbose ("HUP event\n");
 
 	connection_do_close (connection);