aboutsummaryrefslogtreecommitdiffstats
path: root/src/zeroconf-bonjour.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/zeroconf-bonjour.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/zeroconf-bonjour.c')
-rw-r--r--src/zeroconf-bonjour.c71
1 files changed, 19 insertions, 52 deletions
diff --git a/src/zeroconf-bonjour.c b/src/zeroconf-bonjour.c
index 27260ee99..bd613c056 100644
--- a/src/zeroconf-bonjour.c
+++ b/src/zeroconf-bonjour.c
@@ -18,7 +18,6 @@
#include "zeroconf-internal.h"
#include "listen.h"
-#include "ioops.h"
#include <glib.h>
@@ -27,51 +26,8 @@
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "bonjour"
-static struct ioOps zeroConfIo;
-
static DNSServiceRef dnsReference;
-
-static int
-dnsRegisterFdset(fd_set *rfds, G_GNUC_UNUSED fd_set *wfds,
- G_GNUC_UNUSED fd_set *efds)
-{
- int fd;
-
- if (dnsReference == NULL)
- return -1;
-
- fd = DNSServiceRefSockFD(dnsReference);
- if (fd == -1)
- return -1;
-
- FD_SET(fd, rfds);
-
- return fd;
-}
-
-static int
-dnsRegisterFdconsume(int fdCount, fd_set *rfds,
- G_GNUC_UNUSED fd_set *wfds, G_GNUC_UNUSED fd_set *efds)
-{
- int fd;
-
- if (dnsReference == NULL)
- return -1;
-
- fd = DNSServiceRefSockFD(dnsReference);
- if (fd == -1)
- return -1;
-
- if (FD_ISSET(fd, rfds)) {
- FD_CLR(fd, rfds);
-
- DNSServiceProcessResult(dnsReference);
-
- return fdCount - 1;
- }
-
- return fdCount;
-}
+static GIOChannel *bonjour_channel;
static void
dnsRegisterCallback(G_GNUC_UNUSED DNSServiceRef sdRef,
@@ -84,14 +40,22 @@ dnsRegisterCallback(G_GNUC_UNUSED DNSServiceRef sdRef,
if (errorCode != kDNSServiceErr_NoError) {
g_warning("Failed to register zeroconf service.");
- DNSServiceRefDeallocate(dnsReference);
- dnsReference = NULL;
- deregisterIO(&zeroConfIo);
+ bonjour_finish();
} else {
g_debug("Registered zeroconf service with name '%s'", name);
}
}
+static gboolean
+bonjour_channel_event(G_GNUC_UNUSED GIOChannel *source,
+ G_GNUC_UNUSED GIOCondition condition,
+ G_GNUC_UNUSED gpointer data)
+{
+ DNSServiceProcessResult(dnsReference);
+
+ return dnsReference != NULL;
+}
+
void init_zeroconf_osx(const char *serviceName)
{
DNSServiceErrorType error = DNSServiceRegister(&dnsReference,
@@ -112,14 +76,17 @@ void init_zeroconf_osx(const char *serviceName)
return;
}
- zeroConfIo.fdset = dnsRegisterFdset;
- zeroConfIo.consume = dnsRegisterFdconsume;
- registerIO(&zeroConfIo);
+ bonjour_channel = g_io_channel_unix_new(DNSServiceRefSockFD(dnsReference));
+ g_io_add_watch(bonjour_channel, G_IO_IN, bonjour_channel_event, NULL);
}
void bonjour_finish(void)
{
- deregisterIO(&zeroConfIo);
+ if (bonjour_channel != NULL) {
+ g_io_channel_unref(bonjour_channel);
+ bonjour_channel = NULL;
+ }
+
if (dnsReference != NULL) {
DNSServiceRefDeallocate(dnsReference);
dnsReference = NULL;