blobmsg: constify and add more validation
[project/libubox.git] / uloop.c
diff --git a/uloop.c b/uloop.c
index 4d4b223..a263a01 100644 (file)
--- a/uloop.c
+++ b/uloop.c
@@ -116,15 +116,12 @@ static void uloop_run_events(int timeout)
        struct timespec ts;
        int nfds, n;
 
-       if (timeout < 0) {
-               ts.tv_sec = 0;
-               ts.tv_nsec = 0;
-       } else {
+       if (timeout > 0) {
                ts.tv_sec = timeout / 1000;
                ts.tv_nsec = timeout * 1000000;
        }
 
-       nfds = kevent(poll_fd, NULL, 0, events, ARRAY_SIZE(events), &ts);
+       nfds = kevent(poll_fd, NULL, 0, events, ARRAY_SIZE(events), timeout > 0 ? &ts : NULL);
        for(n = 0; n < nfds; ++n)
        {
                struct uloop_fd *u = events[n].udata;
@@ -239,7 +236,7 @@ int uloop_fd_add(struct uloop_fd *sock, unsigned int flags)
        unsigned int fl;
        int ret;
 
-       if (!sock->registered) {
+       if (!sock->registered && !(flags & ULOOP_BLOCKING)) {
                fl = fcntl(sock->fd, F_GETFL, 0);
                fl |= O_NONBLOCK;
                fcntl(sock->fd, F_SETFL, fl);