Bump to libevent 2.1.11
[platform/upstream/libevent.git] / poll.c
diff --git a/poll.c b/poll.c
index 04d311b..fe44071 100644 (file)
--- a/poll.c
+++ b/poll.c
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 #include "event2/event-config.h"
+#include "evconfig-private.h"
+
+#ifdef EVENT__HAVE_POLL
 
 #include <sys/types.h>
-#ifdef _EVENT_HAVE_SYS_TIME_H
+#ifdef EVENT__HAVE_SYS_TIME_H
 #include <sys/time.h>
 #endif
 #include <sys/queue.h>
@@ -48,6 +51,7 @@
 #include "evmap-internal.h"
 #include "event2/thread.h"
 #include "evthread-internal.h"
+#include "time-internal.h"
 
 struct pollidx {
        int idxplus1;
@@ -63,8 +67,8 @@ struct pollop {
 };
 
 static void *poll_init(struct event_base *);
-static int poll_add(struct event_base *, int, short old, short events, void *_idx);
-static int poll_del(struct event_base *, int, short old, short events, void *_idx);
+static int poll_add(struct event_base *, int, short old, short events, void *idx);
+static int poll_del(struct event_base *, int, short old, short events, void *idx);
 static int poll_dispatch(struct event_base *, struct timeval *);
 static void poll_dealloc(struct event_base *);
 
@@ -88,7 +92,9 @@ poll_init(struct event_base *base)
        if (!(pollop = mm_calloc(1, sizeof(struct pollop))))
                return (NULL);
 
-       evsig_init(base);
+       evsig_init_(base);
+
+       evutil_weakrand_seed_(&base->weakrand_seed, 0);
 
        return (pollop);
 }
@@ -127,7 +133,7 @@ poll_dispatch(struct event_base *base, struct timeval *tv)
 
        nfds = pop->nfds;
 
-#ifndef _EVENT_DISABLE_THREAD_SUPPORT
+#ifndef EVENT__DISABLE_THREAD_SUPPORT
        if (base->th_base_lock) {
                /* If we're using this backend in a multithreaded setting,
                 * then we need to work on a copy of event_set, so that we can
@@ -155,7 +161,7 @@ poll_dispatch(struct event_base *base, struct timeval *tv)
 #endif
 
        if (tv != NULL) {
-               msec = evutil_tv_to_msec(tv);
+               msec = evutil_tv_to_msec_(tv);
                if (msec < 0 || msec > INT_MAX)
                        msec = INT_MAX;
        }
@@ -180,7 +186,7 @@ poll_dispatch(struct event_base *base, struct timeval *tv)
        if (res == 0 || nfds == 0)
                return (0);
 
-       i = random() % nfds;
+       i = evutil_weakrand_range_(&base->weakrand_seed, nfds);
        for (j = 0; j < nfds; j++) {
                int what;
                if (++i == nfds)
@@ -192,7 +198,7 @@ poll_dispatch(struct event_base *base, struct timeval *tv)
                res = 0;
 
                /* If the file gets closed notify */
-               if (what & (POLLHUP|POLLERR))
+               if (what & (POLLHUP|POLLERR|POLLNVAL))
                        what |= POLLIN|POLLOUT;
                if (what & POLLIN)
                        res |= EV_READ;
@@ -201,18 +207,18 @@ poll_dispatch(struct event_base *base, struct timeval *tv)
                if (res == 0)
                        continue;
 
-               evmap_io_active(base, event_set[i].fd, res);
+               evmap_io_active_(base, event_set[i].fd, res);
        }
 
        return (0);
 }
 
 static int
-poll_add(struct event_base *base, int fd, short old, short events, void *_idx)
+poll_add(struct event_base *base, int fd, short old, short events, void *idx_)
 {
        struct pollop *pop = base->evbase;
        struct pollfd *pfd = NULL;
-       struct pollidx *idx = _idx;
+       struct pollidx *idx = idx_;
        int i;
 
        EVUTIL_ASSERT((events & EV_SIGNAL) == 0);
@@ -269,11 +275,11 @@ poll_add(struct event_base *base, int fd, short old, short events, void *_idx)
  */
 
 static int
-poll_del(struct event_base *base, int fd, short old, short events, void *_idx)
+poll_del(struct event_base *base, int fd, short old, short events, void *idx_)
 {
        struct pollop *pop = base->evbase;
        struct pollfd *pfd = NULL;
-       struct pollidx *idx = _idx;
+       struct pollidx *idx = idx_;
        int i;
 
        EVUTIL_ASSERT((events & EV_SIGNAL) == 0);
@@ -307,7 +313,7 @@ poll_del(struct event_base *base, int fd, short old, short events, void *_idx)
                 */
                memcpy(&pop->event_set[i], &pop->event_set[pop->nfds],
                       sizeof(struct pollfd));
-               idx = evmap_io_get_fdinfo(&base->io, pop->event_set[i].fd);
+               idx = evmap_io_get_fdinfo_(&base->io, pop->event_set[i].fd);
                EVUTIL_ASSERT(idx);
                EVUTIL_ASSERT(idx->idxplus1 == pop->nfds + 1);
                idx->idxplus1 = i + 1;
@@ -322,7 +328,7 @@ poll_dealloc(struct event_base *base)
 {
        struct pollop *pop = base->evbase;
 
-       evsig_dealloc(base);
+       evsig_dealloc_(base);
        if (pop->event_set)
                mm_free(pop->event_set);
        if (pop->event_set_copy)
@@ -331,3 +337,5 @@ poll_dealloc(struct event_base *base)
        memset(pop, 0, sizeof(struct pollop));
        mm_free(pop);
 }
+
+#endif /* EVENT__HAVE_POLL */