uloop: remove file descriptors if neither read nor write notification is requested

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
This commit is contained in:
Felix Fietkau 2013-01-31 16:43:00 +01:00
parent f24b6294c2
commit 766ff98050

View file

@ -246,6 +246,9 @@ int uloop_fd_delete(struct uloop_fd *sock)
{ {
int i; int i;
if (!sock->registered)
return 0;
for (i = cur_fd + 1; i < cur_nfds; i++) { for (i = cur_fd + 1; i < cur_nfds; i++) {
if (events[i].data.ptr != sock) if (events[i].data.ptr != sock)
continue; continue;
@ -302,6 +305,9 @@ int uloop_fd_add(struct uloop_fd *sock, unsigned int flags)
unsigned int fl; unsigned int fl;
int ret; int ret;
if (!(flags & (ULOOP_READ | ULOOP_WRITE)))
return uloop_fd_delete(sock);
if (!sock->registered && !(flags & ULOOP_BLOCKING)) { if (!sock->registered && !(flags & ULOOP_BLOCKING)) {
fl = fcntl(sock->fd, F_GETFL, 0); fl = fcntl(sock->fd, F_GETFL, 0);
fl |= O_NONBLOCK; fl |= O_NONBLOCK;