From: John Ohl Date: Wed, 10 Dec 2014 02:43:18 +0000 (-0500) Subject: Add support for EV_TIMEOUT to event_base_active_by_fd X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=62df1301ca943011fa9c398323049bcddca2694d;p=libevent Add support for EV_TIMEOUT to event_base_active_by_fd Closes: #194 (cherry-pick) --- diff --git a/event.c b/event.c index 3816650e..bfd94ebd 100644 --- a/event.c +++ b/event.c @@ -3823,7 +3823,35 @@ void event_base_active_by_fd(struct event_base *base, evutil_socket_t fd, short events) { EVBASE_ACQUIRE_LOCK(base, th_base_lock); - evmap_io_active_(base, fd, events & (EV_READ|EV_WRITE|EV_CLOSED)); + + /* Activate any non timer events */ + if (!(events & EV_TIMEOUT)) { + evmap_io_active_(base, fd, events & (EV_READ|EV_WRITE|EV_CLOSED)); + } else { + /* If we want to activate timer events, loop and activate each event with + * the same fd in both the timeheap and common timeouts list */ + int i; + unsigned u; + struct event *ev; + + for (u = 0; u < base->timeheap.n; ++u) { + ev = base->timeheap.p[u]; + if (ev->ev_fd == fd) { + event_active_nolock_(ev, EV_TIMEOUT, 1); + } + } + + for (i = 0; i < base->n_common_timeouts; ++i) { + struct common_timeout_list *ctl = base->common_timeout_queues[i]; + TAILQ_FOREACH(ev, &ctl->events, + ev_timeout_pos.ev_next_with_common_timeout) { + if (ev->ev_fd == fd) { + event_active_nolock_(ev, EV_TIMEOUT, 1); + } + } + } + } + EVBASE_RELEASE_LOCK(base, th_base_lock); } diff --git a/include/event2/event.h b/include/event2/event.h index 1e106f76..c6365a69 100644 --- a/include/event2/event.h +++ b/include/event2/event.h @@ -1586,7 +1586,7 @@ void event_base_dump_events(struct event_base *, FILE *); @param base the event_base on which to activate the events. @param fd An fd to active events on. - @param events One or more of EV_{READ,WRITE}. + @param events One or more of EV_{READ,WRITE,TIMEOUT}. */ EVENT2_EXPORT_SYMBOL void event_base_active_by_fd(struct event_base *base, evutil_socket_t fd, short events); diff --git a/test/regress.c b/test/regress.c index 1c19aad4..02380c01 100644 --- a/test/regress.c +++ b/test/regress.c @@ -3354,6 +3354,7 @@ test_active_by_fd(void *arg) /* Trigger 2, 3, 4 */ event_base_active_by_fd(base, data->pair[0], EV_WRITE); event_base_active_by_fd(base, data->pair[1], EV_READ); + event_base_active_by_fd(base, data->pair[1], EV_TIMEOUT); #ifndef _WIN32 event_base_active_by_signal(base, SIGHUP); #endif @@ -3366,7 +3367,7 @@ test_active_by_fd(void *arg) tt_int_op(e2, ==, EV_WRITE | 0x10000); tt_int_op(e3, ==, EV_READ | 0x10000); /* Mask out EV_WRITE here, since it could be genuinely writeable. */ - tt_int_op((e4 & ~EV_WRITE), ==, EV_READ | 0x10000); + tt_int_op((e4 & ~EV_WRITE), ==, EV_READ | EV_TIMEOUT | 0x10000); #ifndef _WIN32 tt_int_op(es, ==, EV_SIGNAL | 0x10000); #endif