TOR: update to v0.2.5.12
[tomato.git] / release / src / router / tor / src / common / compat_libevent.h
blob9ee7b49cfb9e6d94909f4200bbbcf001415b8834
1 /* Copyright (c) 2009-2013, 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"
9 struct event;
10 struct event_base;
11 #ifdef USE_BUFFEREVENTS
12 struct bufferevent;
13 struct ev_token_bucket_cfg;
14 struct bufferevent_rate_limit_group;
15 #endif
17 #ifdef HAVE_EVENT2_EVENT_H
18 #include <event2/util.h>
19 #elif !defined(EVUTIL_SOCKET_DEFINED)
20 #define EVUTIL_SOCKET_DEFINED
21 #define evutil_socket_t int
22 #endif
24 void configure_libevent_logging(void);
25 void suppress_libevent_log_msg(const char *msg);
27 #ifdef HAVE_EVENT2_EVENT_H
28 #define tor_event_new event_new
29 #define tor_evtimer_new evtimer_new
30 #define tor_evsignal_new evsignal_new
31 #define tor_event_free event_free
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));
36 #else
37 struct event *tor_event_new(struct event_base * base, evutil_socket_t sock,
38 short what, void (*cb)(evutil_socket_t, short, void *), void *arg);
39 struct event *tor_evtimer_new(struct event_base * base,
40 void (*cb)(evutil_socket_t, short, void *), void *arg);
41 struct event *tor_evsignal_new(struct event_base * base, int sig,
42 void (*cb)(evutil_socket_t, short, void *), void *arg);
43 void tor_event_free(struct event *ev);
44 #define tor_evdns_add_server_port evdns_add_server_port
45 #endif
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 #ifdef HAVE_EVENT_BASE_LOOPEXIT
56 #define tor_event_base_loopexit event_base_loopexit
57 #else
58 struct timeval;
59 int tor_event_base_loopexit(struct event_base *base, struct timeval *tv);
60 #endif
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 {
65 /** Flag: if true, disable IOCP (assuming that it could be enabled). */
66 int disable_iocp;
67 /** How many CPUs should we use (relevant only with IOCP). */
68 int num_cpus;
69 /** How many milliseconds should we allow between updating bandwidth limits?
70 * (relevant only with bufferevents). */
71 int msec_per_tick;
72 } tor_libevent_cfg;
74 void tor_libevent_initialize(tor_libevent_cfg *cfg);
75 struct event_base *tor_libevent_get_base(void);
76 const char *tor_libevent_get_method(void);
77 void tor_check_libevent_version(const char *m, int server,
78 const char **badness_out);
79 void tor_check_libevent_header_compatibility(void);
80 const char *tor_libevent_get_version_str(void);
81 const char *tor_libevent_get_header_version_str(void);
83 #ifdef USE_BUFFEREVENTS
84 const struct timeval *tor_libevent_get_one_tick_timeout(void);
85 int tor_libevent_using_iocp_bufferevents(void);
86 int tor_set_bufferevent_rate_limit(struct bufferevent *bev,
87 struct ev_token_bucket_cfg *cfg);
88 int tor_add_bufferevent_to_rate_limit_group(struct bufferevent *bev,
89 struct bufferevent_rate_limit_group *g);
90 #endif
92 int tor_init_libevent_rng(void);
94 void tor_gettimeofday_cached(struct timeval *tv);
95 void tor_gettimeofday_cache_clear(void);
96 #ifdef TOR_UNIT_TESTS
97 void tor_gettimeofday_cache_set(const struct timeval *tv);
98 #endif
99 void tor_gettimeofday_cached_monotonic(struct timeval *tv);
101 #endif