X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-core%2Fnetlink.c;fp=avahi-core%2Fnetlink.c;h=554f25ae17b42e5a65df3917754993679e111315;hb=71cb9656e633111a127779af5923780620792e0b;hp=11961b764f866b795a4d4e3fc2fee8865090c99f;hpb=2a4c962c16dd14529bbc3352507fb8625d6e34c6;p=catta 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) {