Update comments in get_interface_addresses_ioctl
[tor.git] / src / common / compat_libevent.h
blob8ee02c0b6de2d31550f7c2b8031ee42a45cbdd11
1 /* Copyright (c) 2009-2015, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
4 #ifndef TOR_COMPAT_LIBEVENT_H
5 #define TOR_COMPAT_LIBEVENT_H
7 #include "orconfig.h"
8 #include "testsupport.h"
10 struct event;
11 struct event_base;
12 #ifdef USE_BUFFEREVENTS
13 struct bufferevent;
14 struct ev_token_bucket_cfg;
15 struct bufferevent_rate_limit_group;
16 #endif
18 #ifdef HAVE_EVENT2_EVENT_H
19 #include <event2/util.h>
20 #elif !defined(EVUTIL_SOCKET_DEFINED)
21 #define EVUTIL_SOCKET_DEFINED
22 #define evutil_socket_t int
23 #endif
25 void configure_libevent_logging(void);
26 void suppress_libevent_log_msg(const char *msg);
28 #ifdef HAVE_EVENT2_EVENT_H
29 #define tor_event_new event_new
30 #define tor_evtimer_new evtimer_new
31 #define tor_evsignal_new evsignal_new
32 #define tor_evdns_add_server_port(sock, tcp, cb, data) \
33 evdns_add_server_port_with_base(tor_libevent_get_base(), \
34 (sock),(tcp),(cb),(data));
35 #else
36 struct event *tor_event_new(struct event_base * base, evutil_socket_t sock,
37 short what, void (*cb)(evutil_socket_t, short, void *), void *arg);
38 struct event *tor_evtimer_new(struct event_base * base,
39 void (*cb)(evutil_socket_t, short, void *), void *arg);
40 struct event *tor_evsignal_new(struct event_base * base, int sig,
41 void (*cb)(evutil_socket_t, short, void *), void *arg);
42 #define tor_evdns_add_server_port evdns_add_server_port
43 #endif
45 void tor_event_free(struct event *ev);
47 typedef struct periodic_timer_t periodic_timer_t;
49 periodic_timer_t *periodic_timer_new(struct event_base *base,
50 const struct timeval *tv,
51 void (*cb)(periodic_timer_t *timer, void *data),
52 void *data);
53 void periodic_timer_free(periodic_timer_t *);
55 #define tor_event_base_loopexit event_base_loopexit
57 /** Defines a configuration for using libevent with Tor: passed as an argument
58 * to tor_libevent_initialize() to describe how we want to set up. */
59 typedef struct tor_libevent_cfg {
60 /** Flag: if true, disable IOCP (assuming that it could be enabled). */
61 int disable_iocp;
62 /** How many CPUs should we use (relevant only with IOCP). */
63 int num_cpus;
64 /** How many milliseconds should we allow between updating bandwidth limits?
65 * (relevant only with bufferevents). */
66 int msec_per_tick;
67 } tor_libevent_cfg;
69 void tor_libevent_initialize(tor_libevent_cfg *cfg);
70 MOCK_DECL(struct event_base *, tor_libevent_get_base, (void));
71 const char *tor_libevent_get_method(void);
72 void tor_check_libevent_header_compatibility(void);
73 const char *tor_libevent_get_version_str(void);
74 const char *tor_libevent_get_header_version_str(void);
76 #ifdef USE_BUFFEREVENTS
77 const struct timeval *tor_libevent_get_one_tick_timeout(void);
78 int tor_libevent_using_iocp_bufferevents(void);
79 int tor_set_bufferevent_rate_limit(struct bufferevent *bev,
80 struct ev_token_bucket_cfg *cfg);
81 int tor_add_bufferevent_to_rate_limit_group(struct bufferevent *bev,
82 struct bufferevent_rate_limit_group *g);
83 #endif
85 int tor_init_libevent_rng(void);
87 void tor_gettimeofday_cached(struct timeval *tv);
88 void tor_gettimeofday_cache_clear(void);
89 #ifdef TOR_UNIT_TESTS
90 void tor_gettimeofday_cache_set(const struct timeval *tv);
91 #endif
92 void tor_gettimeofday_cached_monotonic(struct timeval *tv);
94 #ifdef COMPAT_LIBEVENT_PRIVATE
95 /** A number representing a version of Libevent.
97 This is a 4-byte number, with the first three bytes representing the
98 major, minor, and patchlevel respectively of the library. The fourth
99 byte is unused.
101 This is equivalent to the format of LIBEVENT_VERSION_NUMBER on Libevent
102 2.0.1 or later. For versions of Libevent before 1.4.0, which followed the
103 format of "1.0, 1.0a, 1.0b", we define 1.0 to be equivalent to 1.0.0, 1.0a
104 to be equivalent to 1.0.1, and so on.
106 typedef uint32_t le_version_t;
108 /** @{ */
109 /** Macros: returns the number of a libevent version as a le_version_t */
110 #define V(major, minor, patch) \
111 (((major) << 24) | ((minor) << 16) | ((patch) << 8))
112 #define V_OLD(major, minor, patch) \
113 V((major), (minor), (patch)-'a'+1)
114 /** @} */
116 /** Represetns a version of libevent so old we can't figure out what version
117 * it is. */
118 #define LE_OLD V(0,0,0)
119 /** Represents a version of libevent so weird we can't figure out what version
120 * it is. */
121 #define LE_OTHER V(0,0,99)
123 STATIC void
124 libevent_logging_callback(int severity, const char *msg);
125 STATIC le_version_t
126 tor_decode_libevent_version(const char *v);
127 STATIC int
128 le_versions_compatibility(le_version_t v);
129 #endif
131 #endif