tor  0.4.2.1-alpha-dev
compat_libevent.h
Go to the documentation of this file.
1 /* Copyright (c) 2009-2019, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
3 
9 #ifndef TOR_COMPAT_LIBEVENT_H
10 #define TOR_COMPAT_LIBEVENT_H
11 
12 #include "orconfig.h"
14 #include "lib/malloc/malloc.h"
15 
17 void suppress_libevent_log_msg(const char *msg);
18 
19 #define tor_event_new event_new
20 #define tor_evtimer_new evtimer_new
21 #define tor_evsignal_new evsignal_new
22 #define tor_evdns_add_server_port(sock, tcp, cb, data) \
23  evdns_add_server_port_with_base(tor_libevent_get_base(), \
24  (sock),(tcp),(cb),(data));
25 
26 struct event;
27 struct event_base;
28 struct timeval;
29 
30 void tor_event_free_(struct event *ev);
31 #define tor_event_free(ev) \
32  FREE_AND_NULL(struct event, tor_event_free_, (ev))
33 
34 typedef struct periodic_timer_t periodic_timer_t;
35 
36 periodic_timer_t *periodic_timer_new(struct event_base *base,
37  const struct timeval *tv,
38  void (*cb)(periodic_timer_t *timer, void *data),
39  void *data);
41 void periodic_timer_launch(periodic_timer_t *, const struct timeval *tv);
43 #define periodic_timer_free(t) \
44  FREE_AND_NULL(periodic_timer_t, periodic_timer_free_, (t))
45 
46 typedef struct mainloop_event_t mainloop_event_t;
48  void *userdata);
50  void (*cb)(mainloop_event_t *, void *),
51  void *userdata);
54  const struct timeval *delay);
57 #define mainloop_event_free(event) \
58  FREE_AND_NULL(mainloop_event_t, mainloop_event_free_, (event))
59 
62 typedef struct tor_libevent_cfg {
64  int num_cpus;
69 
71 MOCK_DECL(struct event_base *, tor_libevent_get_base, (void));
72 const char *tor_libevent_get_method(void);
73 void tor_check_libevent_header_compatibility(void);
74 const char *tor_libevent_get_version_str(void);
75 const char *tor_libevent_get_header_version_str(void);
76 void tor_libevent_free_all(void);
77 
78 int tor_init_libevent_rng(void);
79 
80 #ifdef TOR_UNIT_TESTS
81 void tor_libevent_postfork(void);
82 #endif
83 
84 int tor_libevent_run_event_loop(struct event_base *base, int once);
85 void tor_libevent_exit_loop_after_delay(struct event_base *base,
86  const struct timeval *delay);
87 void tor_libevent_exit_loop_after_callback(struct event_base *base);
88 
89 #ifdef COMPAT_LIBEVENT_PRIVATE
90 
97 #define V(major, minor, patch) \
98  (((major) << 24) | ((minor) << 16) | ((patch) << 8))
99 
100 STATIC void
101 libevent_logging_callback(int severity, const char *msg);
102 #endif /* defined(COMPAT_LIBEVENT_PRIVATE) */
103 
104 #endif /* !defined(TOR_COMPAT_LIBEVENT_H) */
void periodic_timer_launch(periodic_timer_t *, const struct timeval *tv)
void tor_libevent_free_all(void)
const char * tor_libevent_get_header_version_str(void)
const char * tor_libevent_get_version_str(void)
int tor_libevent_run_event_loop(struct event_base *base, int once)
void mainloop_event_activate(mainloop_event_t *event)
Headers for util_malloc.c.
void(* cb)(struct periodic_timer_t *, void *)
const char * tor_libevent_get_method(void)
void mainloop_event_cancel(mainloop_event_t *event)
void mainloop_event_free_(mainloop_event_t *event)
void configure_libevent_logging(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 suppress_libevent_log_msg(const char *msg)
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 *)
mainloop_event_t * mainloop_event_new(void(*cb)(mainloop_event_t *, void *), void *userdata)
STATIC void libevent_logging_callback(int severity, const char *msg)
Macros to implement mocking and selective exposure for the test code.
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:94
void periodic_timer_disable(periodic_timer_t *)
void tor_libevent_initialize(tor_libevent_cfg *cfg)
int mainloop_event_schedule(mainloop_event_t *event, const struct timeval *delay)
void tor_libevent_exit_loop_after_callback(struct event_base *base)
struct tor_libevent_cfg tor_libevent_cfg