From: Felix Fietkau Date: Thu, 31 Jan 2013 15:43:00 +0000 (+0100) Subject: uloop: remove file descriptors if neither read nor write notification is requested X-Git-Url: http://git.archive.openwrt.org/?p=project%2Flibubox.git;a=commitdiff_plain;h=766ff9805074f88846fdc7c8b78b6ae364665356 uloop: remove file descriptors if neither read nor write notification is requested Signed-off-by: Felix Fietkau --- diff --git a/uloop.c b/uloop.c index a3ba3ad..f0ccb0c 100644 --- a/uloop.c +++ b/uloop.c @@ -246,6 +246,9 @@ int uloop_fd_delete(struct uloop_fd *sock) { int i; + if (!sock->registered) + return 0; + for (i = cur_fd + 1; i < cur_nfds; i++) { if (events[i].data.ptr != sock) continue; @@ -302,6 +305,9 @@ int uloop_fd_add(struct uloop_fd *sock, unsigned int flags) unsigned int fl; int ret; + if (!(flags & (ULOOP_READ | ULOOP_WRITE))) + return uloop_fd_delete(sock); + if (!sock->registered && !(flags & ULOOP_BLOCKING)) { fl = fcntl(sock->fd, F_GETFL, 0); fl |= O_NONBLOCK;