From 71cb9656e633111a127779af5923780620792e0b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 24 Oct 2005 23:34:42 +0000 Subject: [PATCH] fix avahi_interface_monitor_sync() for the linux NETLINK implementation git-svn-id: file:///home/lennart/svn/public/avahi/trunk@860 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- avahi-core/iface-linux.c | 3 +-- avahi-core/netlink.c | 53 +++++++++++++++++----------------------- 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/avahi-core/iface-linux.c b/avahi-core/iface-linux.c index bc87152..4fc4add 100644 --- a/avahi-core/iface-linux.c +++ b/avahi-core/iface-linux.c @@ -352,10 +352,9 @@ void avahi_interface_monitor_sync(AvahiInterfaceMonitor *m) { /* Let's handle netlink events until we are done with wild * dumping */ - while (m->osdep.list != LIST_DONE) { + while (!m->list_complete) if (!avahi_netlink_work(m->osdep.netlink, 1) == 0) break; - } /* At this point Avahi knows about all local interfaces and * addresses in existance. */ diff --git a/avahi-core/netlink.c b/avahi-core/netlink.c index 11961b7..554f25a 100644 --- a/avahi-core/netlink.c +++ b/avahi-core/netlink.c @@ -46,41 +46,34 @@ struct AvahiNetlink { }; int avahi_netlink_work(AvahiNetlink *nl, int block) { + ssize_t bytes; + struct nlmsghdr *p; + assert(nl); + + if ((bytes = recv(nl->fd, nl->buffer, nl->buffer_length, block ? 0 : MSG_DONTWAIT)) < 0) { + + if (errno == EAGAIN || errno == EINTR) + return 0; + + avahi_log_error(__FILE__": recv() failed: %s", strerror(errno)); + return -1; + } - for (;;) { - ssize_t bytes; - struct nlmsghdr *p; - - for (;;) { - if ((bytes = recv(nl->fd, nl->buffer, nl->buffer_length, block ? 0 : MSG_DONTWAIT)) < 0) { - - if (errno == EAGAIN || errno == EINTR) - return 0; - - avahi_log_error(__FILE__": recv() failed: %s", strerror(errno)); - return -1; - } - - break; + p = (struct nlmsghdr *) nl->buffer; + + assert(nl->callback); + + for (; bytes > 0; p = NLMSG_NEXT(p, bytes)) { + if (!NLMSG_OK(p, (size_t) bytes)) { + avahi_log_warn(__FILE__": packet truncated"); + return -1; } - - p = (struct nlmsghdr *) nl->buffer; - if (nl->callback) { - for (; bytes > 0; p = NLMSG_NEXT(p, bytes)) { - if (!NLMSG_OK(p, (size_t) bytes)) { - avahi_log_warn(__FILE__": packet truncated"); - return -1; - } - - nl->callback(nl, p, nl->userdata); - } - } - - if (block) - return 1; + nl->callback(nl, p, nl->userdata); } + + return 0; } static void socket_event(AvahiWatch *w, int fd, AvahiWatchEvent event, void *userdata) { -- 2.39.5