diff options
author | Nick Mathewson <nickm@torproject.org> | 2017-10-03 11:09:44 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-04-05 12:36:05 -0400 |
commit | 39cb04335f9fd5c3268c808bac549f531fe389a3 (patch) | |
tree | 493fabac57156ef8fe53304ded4ba50e25adf3dd /src/common | |
parent | f0d2733b468984a7749fb7d506318200ca19e48f (diff) | |
download | tor-39cb04335f9fd5c3268c808bac549f531fe389a3.tar.gz tor-39cb04335f9fd5c3268c808bac549f531fe389a3.zip |
Add wrappers for event_base_loopexit and event_base_loopbreak.
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/compat_libevent.c | 32 | ||||
-rw-r--r-- | src/common/compat_libevent.h | 7 |
2 files changed, 36 insertions, 3 deletions
diff --git a/src/common/compat_libevent.c b/src/common/compat_libevent.c index f453a8e87c..cb311ea462 100644 --- a/src/common/compat_libevent.c +++ b/src/common/compat_libevent.c @@ -363,6 +363,38 @@ tor_libevent_free_all(void) the_event_base = NULL; } +/** + * Run the event loop for the provided event_base, handling events until + * something stops it. If <b>once</b> is set, then just poll-and-run + * once, then exit. Return 0 on success, -1 if an error occurred, or 1 + * if we exited because no events were pending or active. + * + * This isn't reentrant or multithreaded. + */ +int +tor_libevent_run_event_loop(struct event_base *base, int once) +{ + const int flags = once ? EVLOOP_ONCE : 0; + return event_base_loop(base, flags); +} + +/** Tell the event loop to exit after <b>delay</b>. If <b>delay</b> is NULL, + * instead exit after we're done running the currently active events. */ +void +tor_libevent_exit_loop_after_delay(struct event_base *base, + const struct timeval *delay) +{ + event_base_loopexit(base, delay); +} + +/** Tell the event loop to exit after running whichever callback is currently + * active. */ +void +tor_libevent_exit_loop_after_callback(struct event_base *base) +{ + event_base_loopbreak(base); +} + #if defined(LIBEVENT_VERSION_NUMBER) && \ LIBEVENT_VERSION_NUMBER >= V(2,1,1) && \ !defined(TOR_UNIT_TESTS) diff --git a/src/common/compat_libevent.h b/src/common/compat_libevent.h index 711c3a2ebe..86bc77ba5f 100644 --- a/src/common/compat_libevent.h +++ b/src/common/compat_libevent.h @@ -45,9 +45,6 @@ void mainloop_event_free_(mainloop_event_t *event); #define mainloop_event_free(event) \ FREE_AND_NULL(mainloop_event_t, mainloop_event_free_, (event)) -#define tor_event_base_loopexit event_base_loopexit -#define tor_event_base_loopbreak event_base_loopbreak - /** Defines a configuration for using libevent with Tor: passed as an argument * to tor_libevent_initialize() to describe how we want to set up. */ typedef struct tor_libevent_cfg { @@ -75,6 +72,10 @@ void tor_gettimeofday_cache_set(const struct timeval *tv); void tor_libevent_postfork(void); #endif +void tor_libevent_exit_loop_after_delay(struct event_base *base, + const struct timeval *delay); +void tor_libevent_exit_loop_after_callback(struct event_base *base); + #ifdef COMPAT_LIBEVENT_PRIVATE /** Macro: returns the number of a Libevent version as a 4-byte number, |