Tor 0.4.9.0-alpha-dev
compat_libevent.h
Go to the documentation of this file.
1/* Copyright (c) 2009-2021, The Tor Project, Inc. */
2/* See LICENSE for licensing information */
3
4/**
5 * \file compat_libevent.h
6 * \brief Header for compat_libevent.c
7 **/
8
9#ifndef TOR_COMPAT_LIBEVENT_H
10#define TOR_COMPAT_LIBEVENT_H
11
12#include "orconfig.h"
14#include "lib/malloc/malloc.h"
15
16#include <stdbool.h>
17
19void suppress_libevent_log_msg(const char *msg);
20
21#define tor_event_new event_new
22#define tor_evtimer_new evtimer_new
23#define tor_evsignal_new evsignal_new
24#define tor_evdns_add_server_port(sock, tcp, cb, data) \
25 evdns_add_server_port_with_base(tor_libevent_get_base(), \
26 (sock),(tcp),(cb),(data));
27
28struct event;
29struct event_base;
30struct timeval;
31
32void tor_event_free_(struct event *ev);
33#define tor_event_free(ev) \
34 FREE_AND_NULL(struct event, tor_event_free_, (ev))
35
37
38periodic_timer_t *periodic_timer_new(struct event_base *base,
39 const struct timeval *tv,
40 void (*cb)(periodic_timer_t *timer, void *data),
41 void *data);
43void periodic_timer_launch(periodic_timer_t *, const struct timeval *tv);
45#define periodic_timer_free(t) \
46 FREE_AND_NULL(periodic_timer_t, periodic_timer_free_, (t))
47
50 void *userdata);
52 void (*cb)(mainloop_event_t *, void *),
53 void *userdata);
56 const struct timeval *delay);
59#define mainloop_event_free(event) \
60 FREE_AND_NULL(mainloop_event_t, mainloop_event_free_, (event))
61
62/** Defines a configuration for using libevent with Tor: passed as an argument
63 * to tor_libevent_initialize() to describe how we want to set up. */
64typedef struct tor_libevent_cfg_t {
65 /** How many CPUs should we use (not currently useful). */
67 /** How many milliseconds should we allow between updating bandwidth limits?
68 * (Not currently useful). */
71
74MOCK_DECL(struct event_base *, tor_libevent_get_base, (void));
75const char *tor_libevent_get_method(void);
76void tor_check_libevent_header_compatibility(void);
77const char *tor_libevent_get_version_str(void);
79void tor_libevent_free_all(void);
80
81int tor_init_libevent_rng(void);
82
83#ifdef TOR_UNIT_TESTS
84void tor_libevent_postfork(void);
85#endif
86
87int tor_libevent_run_event_loop(struct event_base *base, int once);
88void tor_libevent_exit_loop_after_delay(struct event_base *base,
89 const struct timeval *delay);
90void tor_libevent_exit_loop_after_callback(struct event_base *base);
91
92#ifdef COMPAT_LIBEVENT_PRIVATE
93
94/** Macro: returns the number of a Libevent version as a 4-byte number,
95 with the first three bytes representing the major, minor, and patchlevel
96 respectively of the library. The fourth byte is unused.
97
98 This is equivalent to the format of LIBEVENT_VERSION_NUMBER on Libevent
99 2.0.1 or later. */
100#define V(major, minor, patch) \
101 (((major) << 24) | ((minor) << 16) | ((patch) << 8))
102
103STATIC void
104libevent_logging_callback(int severity, const char *msg);
105#endif /* defined(COMPAT_LIBEVENT_PRIVATE) */
106
107#endif /* !defined(TOR_COMPAT_LIBEVENT_H) */
STATIC void libevent_logging_callback(int severity, const char *msg)
void tor_libevent_initialize(tor_libevent_cfg_t *cfg)
const char * tor_libevent_get_header_version_str(void)
void suppress_libevent_log_msg(const char *msg)
bool tor_libevent_is_initialized(void)
void periodic_timer_free_(periodic_timer_t *)
int mainloop_event_schedule(mainloop_event_t *event, const struct timeval *delay)
void periodic_timer_launch(periodic_timer_t *, const struct timeval *tv)
void mainloop_event_cancel(mainloop_event_t *event)
void tor_libevent_exit_loop_after_callback(struct event_base *base)
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)
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)
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)
const char * tor_libevent_get_method(void)
struct event_base * tor_libevent_get_base(void)
void configure_libevent_logging(void)
void periodic_timer_disable(periodic_timer_t *)
mainloop_event_t * mainloop_event_new(void(*cb)(mainloop_event_t *, void *), void *userdata)
void mainloop_event_activate(mainloop_event_t *event)
Headers for util_malloc.c.
void(* cb)(struct periodic_timer_t *, void *)
Macros to implement mocking and selective exposure for the test code.
#define STATIC
Definition: testsupport.h:32
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:127