aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-02-13 21:10:36 +0100
committerMax Kellermann <max@duempel.org>2012-02-13 21:32:42 +0100
commit03664d0426cd9a10d0f222fbf68e9a43c1f84eb9 (patch)
treedd71ca2e410c95ccd49658f38eb537d202b82cd2
parent652cfb7caf8c0c7ac35043bb56746ef96dfb7c6d (diff)
downloadmpd-03664d0426cd9a10d0f222fbf68e9a43c1f84eb9.tar.gz
mpd-03664d0426cd9a10d0f222fbf68e9a43c1f84eb9.tar.xz
mpd-03664d0426cd9a10d0f222fbf68e9a43c1f84eb9.zip
server_socket: move code to set_fd()
-rw-r--r--src/server_socket.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/server_socket.c b/src/server_socket.c
index 89663d8b8..58b3d234a 100644
--- a/src/server_socket.c
+++ b/src/server_socket.c
@@ -175,6 +175,21 @@ server_socket_in_event(G_GNUC_UNUSED GIOChannel *source,
return true;
}
+static void
+set_fd(struct one_socket *s, int fd)
+{
+ assert(s != NULL);
+ assert(s->fd < 0);
+ assert(fd >= 0);
+
+ s->fd = fd;
+
+ GIOChannel *channel = g_io_channel_new_socket(s->fd);
+ s->source_id = g_io_add_watch(channel, G_IO_IN,
+ server_socket_in_event, s);
+ g_io_channel_unref(channel);
+}
+
bool
server_socket_open(struct server_socket *ss, GError **error_r)
{
@@ -193,10 +208,11 @@ server_socket_open(struct server_socket *ss, GError **error_r)
}
GError *error = NULL;
- s->fd = socket_bind_listen(s->address.sa_family, SOCK_STREAM, 0,
- &s->address, s->address_length, 5,
- &error);
- if (s->fd < 0) {
+ int fd = socket_bind_listen(s->address.sa_family,
+ SOCK_STREAM, 0,
+ &s->address, s->address_length, 5,
+ &error);
+ if (fd < 0) {
if (good != NULL && good->serial == s->serial) {
char *address_string = one_socket_to_string(s);
char *good_string = one_socket_to_string(good);
@@ -228,10 +244,7 @@ server_socket_open(struct server_socket *ss, GError **error_r)
/* register in the GLib main loop */
- GIOChannel *channel = g_io_channel_new_socket(s->fd);
- s->source_id = g_io_add_watch(channel, G_IO_IN,
- server_socket_in_event, s);
- g_io_channel_unref(channel);
+ set_fd(s, fd);
/* mark this socket as "good", and clear previous
errors */