From b3586629c9ce41393898b381159ba331906f8fc3 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 3 Oct 2017 11:20:59 -0400 Subject: [PATCH] Wrap the function we use to run the event loop. Doing this lets us remove the event2/event.h header from a few more modules, particularly in the tests. Part of work on 23750. --- src/common/compat_libevent.h | 1 + src/or/main.c | 4 ++-- src/test/test-timers.c | 4 +--- src/test/test_channelpadding.c | 4 ++-- src/test/test_workqueue.c | 2 +- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/common/compat_libevent.h b/src/common/compat_libevent.h index 86bc77ba5f..c8b0371564 100644 --- a/src/common/compat_libevent.h +++ b/src/common/compat_libevent.h @@ -72,6 +72,7 @@ void tor_gettimeofday_cache_set(const struct timeval *tv); void tor_libevent_postfork(void); #endif +int tor_libevent_run_event_loop(struct event_base *base, int once); 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); diff --git a/src/or/main.c b/src/or/main.c index 9a8ac30886..d1df11af50 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -2832,8 +2832,8 @@ run_main_loop_once(void) * an event, or the second ends, or until we have some active linked * connections to trigger events for. Libevent will wait till one * of these happens, then run all the appropriate callbacks. */ - loop_result = event_base_loop(tor_libevent_get_base(), - called_loop_once ? EVLOOP_ONCE : 0); + loop_result = tor_libevent_run_event_loop(tor_libevent_get_base(), + called_loop_once); if (get_options()->MainloopStats) { /* Update our main loop counters. */ diff --git a/src/test/test-timers.c b/src/test/test-timers.c index 1b4466ecc2..5efd99cacf 100644 --- a/src/test/test-timers.c +++ b/src/test/test-timers.c @@ -7,8 +7,6 @@ #include #include -#include - #include "compat.h" #include "compat_libevent.h" #include "crypto.h" @@ -90,7 +88,7 @@ main(int argc, char **argv) --n_active_timers; } - event_base_loop(tor_libevent_get_base(), 0); + tor_libevent_run_event_loop(tor_libevent_get_base(), 0); int64_t total_difference = 0; uint64_t total_square_difference = 0; diff --git a/src/test/test_channelpadding.c b/src/test/test_channelpadding.c index 072a347de7..2c803c3443 100644 --- a/src/test/test_channelpadding.c +++ b/src/test/test_channelpadding.c @@ -15,7 +15,6 @@ #include "channelpadding.h" #include "compat_libevent.h" #include "config.h" -#include #include "compat_time.h" #include "main.h" #include "networkstatus.h" @@ -264,7 +263,8 @@ dummy_nop_timer(void) timer_schedule(dummy_timer, &timeout); - event_base_loop(tor_libevent_get_base(), 0); + tor_libevent_run_event_loop(tor_libevent_get_base(), 0); + timer_free(dummy_timer); } diff --git a/src/test/test_workqueue.c b/src/test/test_workqueue.c index de7884ff99..2a02611479 100644 --- a/src/test/test_workqueue.c +++ b/src/test/test_workqueue.c @@ -436,7 +436,7 @@ main(int argc, char **argv) tor_libevent_exit_loop_after_delay(tor_libevent_get_base(), &limit); } - event_base_loop(tor_libevent_get_base(), 0); + tor_libevent_run_event_loop(tor_libevent_get_base(), 0); if (n_sent != opt_n_items || n_received+n_successful_cancel != n_sent) { printf("%d vs %d\n", n_sent, opt_n_items);