Tor  0.4.7.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 
19 void 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 
28 struct event;
29 struct event_base;
30 struct timeval;
31 
32 void tor_event_free_(struct event *ev);
33 #define tor_event_free(ev) \
34  FREE_AND_NULL(struct event, tor_event_free_, (ev))
35 
36 typedef struct periodic_timer_t periodic_timer_t;
37 
38 periodic_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);
43 void 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 
48 typedef struct mainloop_event_t mainloop_event_t;
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. */
64 typedef struct tor_libevent_cfg_t {
65  /** How many CPUs should we use (not currently useful). */
66  int num_cpus;
67  /** How many milliseconds should we allow between updating bandwidth limits?
68  * (Not currently useful). */
71 
74 MOCK_DECL(struct event_base *, tor_libevent_get_base, (void));
75 const char *tor_libevent_get_method(void);
76 void tor_check_libevent_header_compatibility(void);
77 const char *tor_libevent_get_version_str(void);
78 const char *tor_libevent_get_header_version_str(void);
79 void tor_libevent_free_all(void);
80 
81 int tor_init_libevent_rng(void);
82 
83 #ifdef TOR_UNIT_TESTS
84 void tor_libevent_postfork(void);
85 #endif
86 
87 int tor_libevent_run_event_loop(struct event_base *base, int once);
88 void tor_libevent_exit_loop_after_delay(struct event_base *base,
89  const struct timeval *delay);
90 void 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 
103 STATIC void
104 libevent_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)
void suppress_libevent_log_msg(const char *msg)
bool tor_libevent_is_initialized(void)
struct event_base * tor_libevent_get_base(void)
void periodic_timer_free_(periodic_timer_t *)
const char * tor_libevent_get_version_str(void)
int mainloop_event_schedule(mainloop_event_t *event, const struct timeval *delay)
void periodic_timer_launch(periodic_timer_t *, const struct timeval *tv)
mainloop_event_t * mainloop_event_postloop_new(void(*cb)(mainloop_event_t *, void *), void *userdata)
void mainloop_event_cancel(mainloop_event_t *event)
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 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)
void tor_libevent_exit_loop_after_delay(struct event_base *base, const struct timeval *delay)
void tor_libevent_free_all(void)
void configure_libevent_logging(void)
void periodic_timer_disable(periodic_timer_t *)
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