2005-04-24 Mikael Hallendal <micke@imendio.com>
authorhallski <hallski>
Sun, 24 Apr 2005 11:40:16 +0000
changeset 114 ebc113e63908
parent 113 093ad250d17c
child 115 f2a921e232e5
2005-04-24 Mikael Hallendal <micke@imendio.com> * loudmouth/lm-connection.c: (_lm_connection_succeeded), (_lm_connection_failed_with_error), (connection_connect_cb), (connection_do_connect), (connection_do_close): - Disconnect from the connect io-watch when connect is done. - Based on a patch from Daniel Lavalliere.
ChangeLog
loudmouth/lm-connection.c
--- a/ChangeLog	Mon Apr 18 16:44:25 2005 +0000
+++ b/ChangeLog	Sun Apr 24 11:40:16 2005 +0000
@@ -1,3 +1,11 @@
+2005-04-24  Mikael Hallendal  <micke@imendio.com>
+
+	* loudmouth/lm-connection.c: (_lm_connection_succeeded),
+	(_lm_connection_failed_with_error), (connection_connect_cb),
+	(connection_do_connect), (connection_do_close):
+	- Disconnect from the connect io-watch when connect is done.
+	- Based on a patch from Daniel Lavalliere.
+
 2005-04-18  Mikael Hallendal  <micke@imendio.com>
 
 	* loudmouth/lm-connection.c: (connection_free):
--- a/loudmouth/lm-connection.c	Mon Apr 18 16:44:25 2005 +0000
+++ b/loudmouth/lm-connection.c	Sun Apr 24 11:40:16 2005 +0000
@@ -76,6 +76,7 @@
 	guint         io_watch_err;
 	guint         io_watch_hup;
 	guint         fd;
+    guint         io_watch_connect;
 	
 	guint         open_id;
 	LmCallback   *open_cb;
@@ -283,6 +284,12 @@
 	gchar        *ch;
 
 	connection = connect_data->connection;
+	
+	if (connection->io_watch_connect != 0) {
+		g_source_destroy (g_main_context_find_source_by_id(connection->context,
+								   connection->io_watch_connect));
+		connection->io_watch_connect = 0;
+	}
 
 	/* Need some way to report error/success */
 	if (connection->cancel_open) {
@@ -383,20 +390,27 @@
 void 
 _lm_connection_failed_with_error (LmConnectData *connect_data, int error) 
 {
+	LmConnection *connection;
+	
 	g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET,
 	       "Connection failed: %s (error %d)\n",
 	       strerror (error), error);
 	
+	connection = connect_data->connection;
+	
 	connect_data->current_addr = connect_data->current_addr->ai_next;
 	
+	if (connection->io_watch_connect != 0) {
+		g_source_destroy (g_main_context_find_source_by_id(connection->context,
+								   connection->io_watch_connect));
+		connection->io_watch_connect = 0;
+	}
+
 	if (connect_data->io_channel != NULL) {
 		g_io_channel_unref (connect_data->io_channel);
 	}
 	
 	if (connect_data->current_addr == NULL) {
-		LmConnection *connection;
-
-		connection = connect_data->connection;
 		if (connection->open_cb && connection->open_cb->func) {
 			LmCallback *cb = connection->open_cb;
 			
@@ -423,13 +437,11 @@
 		       GIOCondition  condition,
 		       gpointer      data) 
 {
-	LmConnection  *connection;
 	LmConnectData *connect_data;
 	int            error;
 	int            len  = sizeof(error);
 
 	connect_data = (LmConnectData *) data;
-	connection   = connect_data->connection;
 	
 	if (condition == G_IO_ERR) {
 		/* get the real error from the socket */
@@ -501,12 +513,14 @@
 	
 	connect_data->io_channel = g_io_channel_unix_new (fd);
 	if (connection->proxy) {
+        connection->io_watch_connect =
 		connection_add_watch (connection,
 				      connect_data->io_channel,
 				      G_IO_OUT|G_IO_ERR,
 				      (GIOFunc) _lm_proxy_connect_cb, 
 				      connect_data);
 	} else {
+        connection->io_watch_connect =
 		connection_add_watch (connection,
 				      connect_data->io_channel,
 				      G_IO_OUT|G_IO_ERR,
@@ -675,10 +689,17 @@
 		g_source_destroy (g_main_context_find_source_by_id (
 			connection->context, connection->io_watch_hup));
 
+		if (connection->io_watch_connect != 0) {
+			g_source_destroy (g_main_context_find_source_by_id(connection->context,
+									   connection->io_watch_connect));
+			connection->io_watch_connect = 0;
+		}
+
 		g_io_channel_unref (connection->io_channel);
 		connection->io_channel = NULL;
 	}
 
+	
 	g_source_destroy (connection->incoming_source);
 	g_source_unref (connection->incoming_source);