compat_libevent.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* Copyright (c) 2009-2013, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. #ifndef TOR_COMPAT_LIBEVENT_H
  4. #define TOR_COMPAT_LIBEVENT_H
  5. #include "orconfig.h"
  6. struct event;
  7. struct event_base;
  8. #ifdef USE_BUFFEREVENTS
  9. struct bufferevent;
  10. struct ev_token_bucket_cfg;
  11. struct bufferevent_rate_limit_group;
  12. #endif
  13. #ifdef HAVE_EVENT2_EVENT_H
  14. #include <event2/util.h>
  15. #elif !defined(EVUTIL_SOCKET_DEFINED)
  16. #define EVUTIL_SOCKET_DEFINED
  17. #define evutil_socket_t int
  18. #endif
  19. void configure_libevent_logging(void);
  20. void suppress_libevent_log_msg(const char *msg);
  21. #ifdef HAVE_EVENT2_EVENT_H
  22. #define tor_event_new event_new
  23. #define tor_evtimer_new evtimer_new
  24. #define tor_evsignal_new evsignal_new
  25. #define tor_event_free event_free
  26. #define tor_evdns_add_server_port(sock, tcp, cb, data) \
  27. evdns_add_server_port_with_base(tor_libevent_get_base(), \
  28. (sock),(tcp),(cb),(data));
  29. #else
  30. struct event *tor_event_new(struct event_base * base, evutil_socket_t sock,
  31. short what, void (*cb)(evutil_socket_t, short, void *), void *arg);
  32. struct event *tor_evtimer_new(struct event_base * base,
  33. void (*cb)(evutil_socket_t, short, void *), void *arg);
  34. struct event *tor_evsignal_new(struct event_base * base, int sig,
  35. void (*cb)(evutil_socket_t, short, void *), void *arg);
  36. void tor_event_free(struct event *ev);
  37. #define tor_evdns_add_server_port evdns_add_server_port
  38. #endif
  39. typedef struct periodic_timer_t periodic_timer_t;
  40. periodic_timer_t *periodic_timer_new(struct event_base *base,
  41. const struct timeval *tv,
  42. void (*cb)(periodic_timer_t *timer, void *data),
  43. void *data);
  44. void periodic_timer_free(periodic_timer_t *);
  45. #ifdef HAVE_EVENT_BASE_LOOPEXIT
  46. #define tor_event_base_loopexit event_base_loopexit
  47. #else
  48. struct timeval;
  49. int tor_event_base_loopexit(struct event_base *base, struct timeval *tv);
  50. #endif
  51. /** Defines a configuration for using libevent with Tor: passed as an argument
  52. * to tor_libevent_initialize() to describe how we want to set up. */
  53. typedef struct tor_libevent_cfg {
  54. /** Flag: if true, disable IOCP (assuming that it could be enabled). */
  55. int disable_iocp;
  56. /** How many CPUs should we use (relevant only with IOCP). */
  57. int num_cpus;
  58. /** How many milliseconds should we allow between updating bandwidth limits?
  59. * (relevant only with bufferevents). */
  60. int msec_per_tick;
  61. } tor_libevent_cfg;
  62. void tor_libevent_initialize(tor_libevent_cfg *cfg);
  63. struct event_base *tor_libevent_get_base(void);
  64. const char *tor_libevent_get_method(void);
  65. void tor_check_libevent_version(const char *m, int server,
  66. const char **badness_out);
  67. void tor_check_libevent_header_compatibility(void);
  68. const char *tor_libevent_get_version_str(void);
  69. #ifdef USE_BUFFEREVENTS
  70. const struct timeval *tor_libevent_get_one_tick_timeout(void);
  71. int tor_libevent_using_iocp_bufferevents(void);
  72. int tor_set_bufferevent_rate_limit(struct bufferevent *bev,
  73. struct ev_token_bucket_cfg *cfg);
  74. int tor_add_bufferevent_to_rate_limit_group(struct bufferevent *bev,
  75. struct bufferevent_rate_limit_group *g);
  76. #endif
  77. void tor_gettimeofday_cached(struct timeval *tv);
  78. void tor_gettimeofday_cache_clear(void);
  79. #endif