aboutsummaryrefslogtreecommitdiffstats
path: root/src/listen.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-12-30 19:24:39 +0100
committerMax Kellermann <max@duempel.org>2008-12-30 19:24:39 +0100
commit71e7ce5d8e3153342494685d60d7ff16d9b29101 (patch)
treeed9893562c16b7f8ab98a5c97bce79bcf1ae2267 /src/listen.c
parent03e650aa9e9a95575fccd51ec9f669abae52fe7e (diff)
downloadmpd-71e7ce5d8e3153342494685d60d7ff16d9b29101.tar.gz
mpd-71e7ce5d8e3153342494685d60d7ff16d9b29101.tar.xz
mpd-71e7ce5d8e3153342494685d60d7ff16d9b29101.zip
main: use the GLib main loop
This is a rather huge patch, which unfortunately cannot be splitted. Instead of using our custom ioops.h library, convert everything to use the GLib main loop.
Diffstat (limited to 'src/listen.c')
-rw-r--r--src/listen.c44
1 files changed, 21 insertions, 23 deletions
diff --git a/src/listen.c b/src/listen.c
index e1cb325cf..94c965f28 100644
--- a/src/listen.c
+++ b/src/listen.c
@@ -55,6 +55,9 @@ static int *listenSockets;
static int numberOfListenSockets;
int boundPort;
+static gboolean
+listen_in_event(GIOChannel *source, GIOCondition condition, gpointer data);
+
static int establishListen(int pf, const struct sockaddr *addrp,
socklen_t addrlen)
{
@@ -63,6 +66,7 @@ static int establishListen(int pf, const struct sockaddr *addrp,
#ifdef HAVE_STRUCT_UCRED
int passcred = 1;
#endif
+ GIOChannel *channel;
if ((sock = socket(pf, SOCK_STREAM, 0)) < 0)
g_error("socket < 0");
@@ -90,6 +94,11 @@ static int establishListen(int pf, const struct sockaddr *addrp,
listenSockets[numberOfListenSockets - 1] = 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);
+
return 0;
}
@@ -223,17 +232,6 @@ void listenOnPort(void)
} while ((param = getNextConfigParam(CONF_BIND_TO_ADDRESS, param)));
}
-void addListenSocketsToFdSet(fd_set * fds, int *fdmax)
-{
- int i;
-
- for (i = 0; i < numberOfListenSockets; i++) {
- FD_SET(listenSockets[i], fds);
- if (listenSockets[i] > *fdmax)
- *fdmax = listenSockets[i];
- }
-}
-
void closeAllListenSockets(void)
{
int i;
@@ -266,21 +264,21 @@ static int get_remote_uid(int fd)
#endif
}
-void getConnections(fd_set * fds)
+static gboolean
+listen_in_event(G_GNUC_UNUSED GIOChannel *source,
+ G_GNUC_UNUSED GIOCondition condition,
+ gpointer data)
{
- int i;
- int fd = 0;
+ int listen_fd = GPOINTER_TO_INT(data), fd;
struct sockaddr sockAddr;
socklen_t socklen = sizeof(sockAddr);
- for (i = 0; i < numberOfListenSockets; i++) {
- if (FD_ISSET(listenSockets[i], fds)) {
- if ((fd = accept(listenSockets[i], &sockAddr, &socklen))
- >= 0) {
- client_new(fd, &sockAddr, get_remote_uid(fd));
- } else if (fd < 0 && errno != EINTR) {
- g_warning("Problems accept()'ing");
- }
- }
+ fd = accept(listen_fd, &sockAddr, &socklen);
+ if (fd >= 0) {
+ client_new(fd, &sockAddr, get_remote_uid(fd));
+ } else if (fd < 0 && errno != EINTR) {
+ g_warning("Problems accept()'ing");
}
+
+ return true;
}