From 83740555ea8664da0830f88a1dd5afa69880bb40 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 28 Jul 2011 14:09:13 +0200 Subject: [PATCH] tevent: Slightly simplify poll_event_loop_poll No real code change. Do an early return instead of an if-statement, avoiding one level of indentation. --- lib/tevent/tevent_poll.c | 71 ++++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/lib/tevent/tevent_poll.c b/lib/tevent/tevent_poll.c index 0b782e99bb8..0a9c0f0b5ce 100644 --- a/lib/tevent/tevent_poll.c +++ b/lib/tevent/tevent_poll.c @@ -222,40 +222,45 @@ static int poll_event_loop_poll(struct tevent_context *ev, return 0; } - if (pollrtn > 0) { - /* at least one file descriptor is ready - check - which ones and call the handler, being careful to allow - the handler to remove itself when called */ - for (fde = ev->fd_events; fde; fde = fde->next) { - struct pollfd *pfd; - uint64_t pfd_idx = fde->additional_flags; - uint16_t flags = 0; - - pfd = &poll_ev->fds[pfd_idx]; - - if (pfd->revents & (POLLHUP|POLLERR)) { - /* If we only wait for TEVENT_FD_WRITE, we - should not tell the event handler about it, - and remove the writable flag, as we only - report errors when waiting for read events - to match the select behavior. */ - if (!(fde->flags & TEVENT_FD_READ)) { - TEVENT_FD_NOT_WRITEABLE(fde); - continue; - } - flags |= TEVENT_FD_READ; - } - if (pfd->revents & POLLIN) { - flags |= TEVENT_FD_READ; - } - if (pfd->revents & POLLOUT) { - flags |= TEVENT_FD_WRITE; - } - if (flags != 0) { - fde->handler(ev, fde, flags, - fde->private_data); - break; + if (pollrtn <= 0) { + /* + * No fd's ready + */ + return 0; + } + + /* at least one file descriptor is ready - check + which ones and call the handler, being careful to allow + the handler to remove itself when called */ + + for (fde = ev->fd_events; fde; fde = fde->next) { + struct pollfd *pfd; + uint64_t pfd_idx = fde->additional_flags; + uint16_t flags = 0; + + pfd = &poll_ev->fds[pfd_idx]; + + if (pfd->revents & (POLLHUP|POLLERR)) { + /* If we only wait for TEVENT_FD_WRITE, we + should not tell the event handler about it, + and remove the writable flag, as we only + report errors when waiting for read events + to match the select behavior. */ + if (!(fde->flags & TEVENT_FD_READ)) { + TEVENT_FD_NOT_WRITEABLE(fde); + continue; } + flags |= TEVENT_FD_READ; + } + if (pfd->revents & POLLIN) { + flags |= TEVENT_FD_READ; + } + if (pfd->revents & POLLOUT) { + flags |= TEVENT_FD_WRITE; + } + if (flags != 0) { + fde->handler(ev, fde, flags, fde->private_data); + break; } } -- 2.11.4.GIT