Close the socket before setting it to -1. This hopefully solves LM-95.
Added a socket_close_io_channel call that unrefs the IOChannel and closes the
file descriptor.
--- a/loudmouth/lm-socket.c Mon Feb 25 23:58:43 2008 +0100
+++ b/loudmouth/lm-socket.c Thu Feb 28 02:18:11 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;
}
}