Merge branch 'master' of git@github.com:hallski/loudmouth
authorMikael Hallendal <micke@imendio.com>
Thu, 28 Feb 2008 02:21:47 +0100
changeset 347 92cbc1e51a44
parent 346 ca353cc81e9a (diff)
parent 345 9a94f040cc56 (current diff)
child 348 48fdfa327cc7
Merge branch 'master' of git@github.com:hallski/loudmouth
--- a/loudmouth/lm-socket.c	Thu Feb 28 01:13:52 2008 +0100
+++ b/loudmouth/lm-socket.c	Thu Feb 28 02:21:47 2008 +0100
@@ -124,6 +124,7 @@
 					       int             srv_len, 
 					       gchar         **out_server, 
 					       guint          *out_port);
+static void         socket_close_io_channel   (GIOChannel     *io_channel);
 
 static void
 socket_free (LmSocket *socket)
@@ -452,8 +453,7 @@
 	}
 
 	if (connect_data->io_channel != NULL) {
-		g_io_channel_unref (connect_data->io_channel);
-		/* FIXME: need to check for last unref and close the socket */
+		socket_close_io_channel (connect_data->io_channel);
 	}
 	
 	if (connect_data->current_addr == NULL) {
@@ -783,6 +783,21 @@
 }
 
 static void
+socket_close_io_channel (GIOChannel *io_channel)
+{
+	gint fd;
+
+	g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, 
+	       "Freeing up IOChannel and file descriptor\n");
+
+	fd = g_io_channel_unix_get_fd (io_channel);
+
+	g_io_channel_unref (io_channel);
+
+	_lm_sock_close (fd);
+}
+
+static void
 _lm_socket_create_phase1 (LmSocket *socket, unsigned char *srv_ans, int len);
 static void
 _lm_socket_create_phase2 (LmSocket *socket, struct addrinfo *ans);
@@ -1148,9 +1163,9 @@
 			socket->watch_out = NULL;
 		}
 
-		g_io_channel_unref (socket->io_channel);
+		socket_close_io_channel (socket->io_channel);
+
 		socket->io_channel = NULL;
-
 		socket->fd = -1;
 	}
 }