diff options
author | Max Kellermann <max@duempel.org> | 2009-01-10 18:55:29 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-01-10 18:55:29 +0100 |
commit | d60cf67d1972dcf176117b7b3b1f5077c906353e (patch) | |
tree | 301450049843e606a9840a4352e62c74db84c783 /src/listen.c | |
parent | a673d6be98e90f61a4f1fda72ff5982fce3494d0 (diff) | |
download | mpd-d60cf67d1972dcf176117b7b3b1f5077c906353e.tar.gz mpd-d60cf67d1972dcf176117b7b3b1f5077c906353e.tar.xz mpd-d60cf67d1972dcf176117b7b3b1f5077c906353e.zip |
listen: added struct listen_socket
Make the listen socket an object, allowing us to add more fields
later. Convert listenSockets into a simple linked list.
Diffstat (limited to 'src/listen.c')
-rw-r--r-- | src/listen.c | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/src/listen.c b/src/listen.c index 9f7577de1..62d4e2e60 100644 --- a/src/listen.c +++ b/src/listen.c @@ -54,8 +54,13 @@ port, strerror(errno)); \ } while (0); -static int *listenSockets; -static int numberOfListenSockets; +struct listen_socket { + struct listen_socket *next; + + int fd; +}; + +static struct listen_socket *listen_sockets; int boundPort; static gboolean @@ -69,6 +74,7 @@ static int establishListen(int pf, const struct sockaddr *addrp, #ifdef HAVE_STRUCT_UCRED int passcred = 1; #endif + struct listen_socket *ls; GIOChannel *channel; if ((sock = socket(pf, SOCK_STREAM, 0)) < 0) @@ -91,17 +97,17 @@ static int establishListen(int pf, const struct sockaddr *addrp, setsockopt(sock, SOL_SOCKET, SO_PASSCRED, &passcred, sizeof(passcred)); #endif - numberOfListenSockets++; - listenSockets = g_realloc(listenSockets, sizeof(listenSockets[0]) * - numberOfListenSockets); - - listenSockets[numberOfListenSockets - 1] = sock; + ls = g_new(struct listen_socket, 1); + ls->fd = sock; channel = g_io_channel_unix_new(sock); g_io_add_watch(channel, G_IO_IN, listen_in_event, GINT_TO_POINTER(sock)); g_io_channel_unref(channel); + ls->next = listen_sockets; + listen_sockets = ls; + return 0; } @@ -269,18 +275,15 @@ void listenOnPort(void) void closeAllListenSockets(void) { - int i; - g_debug("closeAllListenSockets called"); - for (i = 0; i < numberOfListenSockets; i++) { - g_debug("closing listen socket %i", i); - while (close(listenSockets[i]) < 0 && errno == EINTR) ; - } + while (listen_sockets != NULL) { + struct listen_socket *ls = listen_sockets; + listen_sockets = ls->next; - numberOfListenSockets = 0; - g_free(listenSockets); - listenSockets = NULL; + close(ls->fd); + g_free(ls); + } } static int get_remote_uid(int fd) |