]> granicus.if.org Git - libevent/commitdiff
Add support for EV_TIMEOUT to event_base_active_by_fd
authorJohn Ohl <john@collabriasoftware.com>
Wed, 10 Dec 2014 02:43:18 +0000 (21:43 -0500)
committerAzat Khuzhin <azat@libevent.org>
Sat, 25 May 2019 18:25:10 +0000 (21:25 +0300)
Closes: #194 (cherry-pick)
(cherry picked from commit 62df1301ca943011fa9c398323049bcddca2694d)

event.c
include/event2/event.h
test/regress.c

diff --git a/event.c b/event.c
index 3816650e6b73b14db8dfd10290c34c7d9e1d1c82..bfd94ebd05447c7a1837859df1a59eadc62f4f67 100644 (file)
--- 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);
 }
 
index 1e106f76e4b8327c7a957b846cae12ce220cf172..c6365a6940db0b5d6c898428e6d92a3c8d43c971 100644 (file)
@@ -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);
index 1c19aad4fc04e66aa3acaa0352cee59f9cea9a85..02380c0121af4c20db0c98351aa8fdcb6751fe13 100644 (file)
@@ -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