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:
72tor_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
140 struct event_config *cfg;
142 cfg = event_config_new();
147 event_config_set_flag(cfg, EVENT_BASE_FLAG_NOLOCK);
150 event_config_set_num_cpus_hint(cfg, torcfg->
num_cpus);
154 event_config_set_flag(cfg, EVENT_BASE_FLAG_EPOLL_USE_CHANGELIST);
158 event_config_free(cfg);
163 log_err(
LD_GENERAL,
"Unable to initialize Libevent: cannot continue.");
172 log_err(
LD_GENERAL,
"Unable to create rescan event: cannot continue.");
178 "Initialized libevent version %s using method %s. Good.",
212 return event_get_version();
220 return LIBEVENT_VERSION;
240 timer->
cb(timer, timer->
data);
257 if (!(timer->
ev = tor_event_new(base, -1, EV_PERSIST,
278 if (event_pending(timer->
ev, EV_TIMEOUT, NULL))
280 event_add(timer->
ev, tv);
294 (void) event_del(timer->
ev);
303 tor_event_free(timer->
ev);
333 mev->cb(mev, mev->userdata);
358 mev->cb(mev, mev->userdata);
373 mev->ev = tor_event_new(base, -1, 0,
378 mev->userdata = userdata;
426 event_active(event->ev, EV_READ, 1);
444 if (BUG(tv == NULL)) {
450 return event_add(event->ev, tv);
460 (void) event_del(event->ev);
469 tor_event_free(event->ev);
470 memset(event, 0xb8,
sizeof(*event));
475tor_init_libevent_rng(
void)
479 if (evutil_secure_rng_init() < 0) {
483#ifdef HAVE_EVUTIL_SECURE_RNG_ADD_BYTES
484 evutil_secure_rng_add_bytes(buf, 32);
486 evutil_secure_rng_get_bytes(buf,
sizeof(buf));
513 const int flags = once ? EVLOOP_ONCE : 0;
514 return event_base_loop(base, flags);
523 event_base_loopexit(base, delay);
531 event_base_loopbreak(base);
534#if defined(TOR_UNIT_TESTS)
538tor_libevent_postfork(
void)
STATIC void libevent_logging_callback(int severity, const char *msg)
const char * tor_libevent_get_header_version_str(void)
void suppress_libevent_log_msg(const char *msg)
bool tor_libevent_is_initialized(void)
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
void tor_libevent_exit_loop_after_callback(struct event_base *base)
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_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)
mainloop_event_t * mainloop_event_postloop_new(void(*cb)(mainloop_event_t *, void *), void *userdata)
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)
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 periodic_timer_free_(periodic_timer_t *timer)
static const char * suppress_msg
const char * tor_libevent_get_method(void)
struct event_base * tor_libevent_get_base(void)
void configure_libevent_logging(void)
static mainloop_event_t * mainloop_event_new_impl(int postloop, void(*cb)(mainloop_event_t *, void *), void *userdata)
void periodic_timer_disable(periodic_timer_t *timer)
mainloop_event_t * mainloop_event_new(void(*cb)(mainloop_event_t *, void *), void *userdata)
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.