10 #define COMPAT_LIBEVENT_PRIVATE
18 #include <event2/event.h>
19 #include <event2/thread.h>
33 n = strlcpy(buf, msg,
sizeof(buf));
34 if (n && n <
sizeof(buf) && buf[n-1] ==
'\n') {
38 case _EVENT_LOG_DEBUG:
72 tor_event_free_(
struct event *ev)
113 struct event_base *the_base = arg;
114 event_base_loopbreak(the_base);
123 #ifdef __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
124 #define MACOSX_KQUEUE_IS_BROKEN \
125 (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1040)
127 #define MACOSX_KQUEUE_IS_BROKEN 0
141 struct event_config *cfg;
144 cfg = event_config_new();
149 event_config_set_flag(cfg, EVENT_BASE_FLAG_NOLOCK);
152 event_config_set_num_cpus_hint(cfg, torcfg->
num_cpus);
156 event_config_set_flag(cfg, EVENT_BASE_FLAG_EPOLL_USE_CHANGELIST);
160 event_config_free(cfg);
165 log_err(
LD_GENERAL,
"Unable to initialize Libevent: cannot continue.");
174 log_err(
LD_GENERAL,
"Unable to create rescan event: cannot continue.");
180 "Initialized libevent version %s using method %s. Good.",
214 return event_get_version();
222 return LIBEVENT_VERSION;
242 timer->
cb(timer, timer->
data);
259 if (!(timer->
ev = tor_event_new(base, -1, EV_PERSIST,
280 if (event_pending(timer->
ev, EV_TIMEOUT, NULL))
282 event_add(timer->
ev, tv);
296 (void) event_del(timer->
ev);
305 tor_event_free(timer->
ev);
335 mev->cb(mev, mev->userdata);
360 mev->cb(mev, mev->userdata);
375 mev->ev = tor_event_new(base, -1, 0,
380 mev->userdata = userdata;
428 event_active(event->ev, EV_READ, 1);
446 if (BUG(tv == NULL)) {
452 return event_add(event->ev, tv);
462 (void) event_del(event->ev);
471 tor_event_free(event->ev);
472 memset(event, 0xb8,
sizeof(*event));
477 tor_init_libevent_rng(
void)
481 if (evutil_secure_rng_init() < 0) {
485 #ifdef HAVE_EVUTIL_SECURE_RNG_ADD_BYTES
486 evutil_secure_rng_add_bytes(buf, 32);
488 evutil_secure_rng_get_bytes(buf,
sizeof(buf));
515 const int flags = once ? EVLOOP_ONCE : 0;
516 return event_base_loop(base, flags);
525 event_base_loopexit(base, delay);
533 event_base_loopbreak(base);
536 #if defined(TOR_UNIT_TESTS)
540 tor_libevent_postfork(
void)
STATIC void libevent_logging_callback(int severity, const char *msg)
void suppress_libevent_log_msg(const char *msg)
bool tor_libevent_is_initialized(void)
struct event_base * tor_libevent_get_base(void)
static mainloop_event_t * mainloop_event_new_impl(int postloop, void(*cb)(mainloop_event_t *, void *), void *userdata)
const char * tor_libevent_get_version_str(void)
mainloop_event_t * mainloop_event_postloop_new(void(*cb)(mainloop_event_t *, void *), void *userdata)
void mainloop_event_cancel(mainloop_event_t *event)
void periodic_timer_launch(periodic_timer_t *timer, const struct timeval *tv)
static struct event_base * the_event_base
const char * tor_libevent_get_method(void)
periodic_timer_t * periodic_timer_new(struct event_base *base, const struct timeval *tv, void(*cb)(periodic_timer_t *timer, void *data), void *data)
void tor_libevent_exit_loop_after_callback(struct event_base *base)
mainloop_event_t * mainloop_event_new(void(*cb)(mainloop_event_t *, void *), void *userdata)
void tor_libevent_initialize(tor_libevent_cfg_t *torcfg)
void mainloop_event_free_(mainloop_event_t *event)
int tor_libevent_run_event_loop(struct event_base *base, int once)
const char * tor_libevent_get_header_version_str(void)
static void mainloop_event_cb(evutil_socket_t fd, short what, void *arg)
void tor_libevent_exit_loop_after_delay(struct event_base *base, const struct timeval *delay)
static void periodic_timer_cb(evutil_socket_t fd, short what, void *arg)
int mainloop_event_schedule(mainloop_event_t *event, const struct timeval *tv)
void tor_libevent_free_all(void)
void periodic_timer_free_(periodic_timer_t *timer)
static const char * suppress_msg
void configure_libevent_logging(void)
void periodic_timer_disable(periodic_timer_t *timer)
void mainloop_event_activate(mainloop_event_t *event)
static void mainloop_event_postloop_cb(evutil_socket_t fd, short what, void *arg)
Header for compat_libevent.c.
Header for compat_string.c.
void crypto_rand(char *to, size_t n)
Common functions for using (pseudo-)random number generators.
static void rescan_mainloop_cb(evutil_socket_t fd, short events, void *arg)
static struct event * rescan_mainloop_ev
void(* cb)(struct periodic_timer_t *, void *)
#define MOCK_IMPL(rv, funcname, arglist)
Macros to manage assertions, fatal and non-fatal.