Back to index

tor  0.2.3.19-rc
compat_libevent.h
Go to the documentation of this file.
00001 /* Copyright (c) 2009-2012, The Tor Project, Inc. */
00002 /* See LICENSE for licensing information */
00003 
00004 #ifndef _TOR_COMPAT_LIBEVENT_H
00005 #define _TOR_COMPAT_LIBEVENT_H
00006 
00007 #include "orconfig.h"
00008 
00009 struct event;
00010 struct event_base;
00011 #ifdef USE_BUFFEREVENTS
00012 struct bufferevent;
00013 struct ev_token_bucket_cfg;
00014 struct bufferevent_rate_limit_group;
00015 #endif
00016 
00017 #ifdef HAVE_EVENT2_EVENT_H
00018 #include <event2/util.h>
00019 #elif !defined(EVUTIL_SOCKET_DEFINED)
00020 #define EVUTIL_SOCKET_DEFINED
00021 #define evutil_socket_t int
00022 #endif
00023 
00024 void configure_libevent_logging(void);
00025 void suppress_libevent_log_msg(const char *msg);
00026 
00027 #ifdef HAVE_EVENT2_EVENT_H
00028 #define tor_event_new     event_new
00029 #define tor_evtimer_new   evtimer_new
00030 #define tor_evsignal_new  evsignal_new
00031 #define tor_event_free    event_free
00032 #define tor_evdns_add_server_port(sock, tcp, cb, data) \
00033   evdns_add_server_port_with_base(tor_libevent_get_base(), \
00034   (sock),(tcp),(cb),(data));
00035 
00036 #else
00037 struct event *tor_event_new(struct event_base * base, evutil_socket_t sock,
00038            short what, void (*cb)(evutil_socket_t, short, void *), void *arg);
00039 struct event *tor_evtimer_new(struct event_base * base,
00040             void (*cb)(evutil_socket_t, short, void *), void *arg);
00041 struct event *tor_evsignal_new(struct event_base * base, int sig,
00042             void (*cb)(evutil_socket_t, short, void *), void *arg);
00043 void tor_event_free(struct event *ev);
00044 #define tor_evdns_add_server_port evdns_add_server_port
00045 #endif
00046 
00047 typedef struct periodic_timer_t periodic_timer_t;
00048 
00049 periodic_timer_t *periodic_timer_new(struct event_base *base,
00050              const struct timeval *tv,
00051              void (*cb)(periodic_timer_t *timer, void *data),
00052              void *data);
00053 void periodic_timer_free(periodic_timer_t *);
00054 
00055 #ifdef HAVE_EVENT_BASE_LOOPEXIT
00056 #define tor_event_base_loopexit event_base_loopexit
00057 #else
00058 struct timeval;
00059 int tor_event_base_loopexit(struct event_base *base, struct timeval *tv);
00060 #endif
00061 
00064 typedef struct tor_libevent_cfg {
00066   int disable_iocp;
00068   int num_cpus;
00071   int msec_per_tick;
00072 } tor_libevent_cfg;
00073 
00074 void tor_libevent_initialize(tor_libevent_cfg *cfg);
00075 struct event_base *tor_libevent_get_base(void);
00076 const char *tor_libevent_get_method(void);
00077 void tor_check_libevent_version(const char *m, int server,
00078                                 const char **badness_out);
00079 void tor_check_libevent_header_compatibility(void);
00080 const char *tor_libevent_get_version_str(void);
00081 
00082 #ifdef USE_BUFFEREVENTS
00083 const struct timeval *tor_libevent_get_one_tick_timeout(void);
00084 int tor_libevent_using_iocp_bufferevents(void);
00085 int tor_set_bufferevent_rate_limit(struct bufferevent *bev,
00086                                    struct ev_token_bucket_cfg *cfg);
00087 int tor_add_bufferevent_to_rate_limit_group(struct bufferevent *bev,
00088                                    struct bufferevent_rate_limit_group *g);
00089 #endif
00090 
00091 void tor_gettimeofday_cached(struct timeval *tv);
00092 void tor_gettimeofday_cache_clear(void);
00093 
00094 #endif
00095