From 563492a0c85d813bf6915ea6dcf9743be61d1cbc Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Fri, 23 Mar 2012 16:59:42 +0100 Subject: [PATCH] eloop: remove fd from epoll-set on HUP If a handler does not correctly remove itself on HUP, the epoll-loop will never sleep again because the fd will always be notified as HUP. Therefore, remove the fd from the epoll-set directly on HUP. This doesn't change application behavior so it is safe here. This also allows other subsystems to ignore HUP/ERR events if they are not fatal. The FD won't be readded but that may not bother. Signed-off-by: David Herrmann --- src/eloop.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/eloop.c b/src/eloop.c index 7f06cda..e81321f 100644 --- a/src/eloop.c +++ b/src/eloop.c @@ -798,10 +798,12 @@ int ev_eloop_dispatch(struct ev_eloop *loop, int timeout) mask |= EV_READABLE; if (ep[i].events & EPOLLOUT) mask |= EV_WRITEABLE; - if (ep[i].events & EPOLLHUP) - mask |= EV_HUP; if (ep[i].events & EPOLLERR) mask |= EV_ERR; + if (ep[i].events & EPOLLHUP) { + mask |= EV_HUP; + epoll_ctl(loop->efd, EPOLL_CTL_DEL, fd->fd, NULL); + } fd->cb(fd, mask, fd->data); }