X-Git-Url: http://git.archive.openwrt.org/?p=project%2Flibubox.git;a=blobdiff_plain;f=uloop.c;h=f0ccb0c2e6344400853bd8548355328f19feb06f;hp=4095d5b4069cfc768b6c6774123d79bc73a88aa8;hb=bd47d85d38ee5fb1fb8a37d006f51443f67a2061;hpb=569bc29c5a0821ef24d5e679add2e1a61542ae91 diff --git a/uloop.c b/uloop.c index 4095d5b..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; @@ -387,6 +393,18 @@ int uloop_timeout_cancel(struct uloop_timeout *timeout) return 0; } +int uloop_timeout_remaining(struct uloop_timeout *timeout) +{ + struct timeval now; + + if (!timeout->pending) + return -1; + + uloop_gettime(&now); + + return tv_diff(&timeout->time, &now); +} + int uloop_process_add(struct uloop_process *p) { struct uloop_process *tmp;