#include "dns_sd.h"
enum {
- COMMAND_COME_AGAIN = 0,
COMMAND_POLL = 'p',
COMMAND_QUIT = 'q',
COMMAND_POLL_DONE = 'P',
assert(fd >= 0);
if ((r = read(fd, &command, 1)) != 1) {
-
- if (errno == EAGAIN)
- return COMMAND_COME_AGAIN;
-
fprintf(stderr, __FILE__": read() failed: %s\n", r < 0 ? strerror(errno) : "EOF");
return -1;
}
return 0;
}
-static int set_nonblock(int fd) {
- int n;
-
- assert(fd >= 0);
-
- if ((n = fcntl(fd, F_GETFL)) < 0)
- return -1;
-
- if (n & O_NONBLOCK)
- return 0;
-
- return fcntl(fd, F_SETFL, n|O_NONBLOCK);
-}
-
-
static int poll_func(struct pollfd *ufds, unsigned int nfds, int timeout, void *userdata) {
DNSServiceRef sdref = userdata;
int ret;
case COMMAND_QUIT:
return NULL;
-
- case COMMAND_COME_AGAIN:
- break;
}
}
sdref->thread_fd = fd[0];
sdref->main_fd = fd[1];
- set_nonblock(sdref->main_fd);
-
sdref->client = NULL;
sdref->service_browser = NULL;
sdref->service_resolver = NULL;
DNSServiceErrorType DNSSD_API DNSServiceProcessResult(DNSServiceRef sdref) {
DNSServiceErrorType ret = kDNSServiceErr_Unknown;
- int t;
assert(sdref);
assert(sdref->n_ref >= 1);
ASSERT_SUCCESS(pthread_mutex_lock(&sdref->mutex));
/* Cleanup notification socket */
- if ((t = read_command(sdref->main_fd)) != COMMAND_POLL_DONE) {
- if (t == COMMAND_COME_AGAIN)
- ret = kDNSServiceErr_Unknown;
+ if (read_command(sdref->main_fd) != COMMAND_POLL_DONE)
goto finish;
- }
if (avahi_simple_poll_dispatch(sdref->simple_poll) < 0)
goto finish;