From e35c065d77ea35a75b4d3b0aa677eee3eff62732 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Tue, 14 Nov 2017 12:51:27 +0100 Subject: [PATCH] uev.c: Stop I/O watcher immediately on EPOLLERR or EPOLLHUP No need to check fd with fcntl(). On EPOLLERR the descriptor has an error condition that must bed ACK'ed by the callback. On EPOLLHUP we got a hang-up on the remote end, usually a stream or pipe, either way the callback must ACK this too, regardless. Signed-off-by: Joachim Nilsson --- src/uev.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/uev.c b/src/uev.c index af19444..d18bb4f 100644 --- a/src/uev.c +++ b/src/uev.c @@ -52,12 +52,6 @@ static int _init(uev_ctx_t *ctx, int close_old) return 0; } -/* Simple check if a descriptor is still valid in the kernel */ -static int is_valid_fd(int fd) -{ - return fcntl(fd, F_GETFL) != -1 || errno != EBADF; -} - /* Used by file i/o workaround when epoll => EPERM */ static int has_data(int fd) { @@ -332,10 +326,8 @@ int uev_run(uev_ctx_t *ctx, int flags) switch (w->type) { case UEV_IO_TYPE: - if (events & (EPOLLHUP | EPOLLERR)) { - if (!is_valid_fd(w->fd)) - uev_io_stop(w); - } + if (events & (EPOLLHUP | EPOLLERR)) + uev_io_stop(w); break; case UEV_SIGNAL_TYPE: