compat_libevent.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* Copyright (c) 2009-2016, 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. #include "testsupport.h"
  7. #include <event2/event.h>
  8. #ifdef USE_BUFFEREVENTS
  9. #include <event2/bufferevent.h>
  10. #endif
  11. void configure_libevent_logging(void);
  12. void suppress_libevent_log_msg(const char *msg);
  13. #define tor_event_new event_new
  14. #define tor_evtimer_new evtimer_new
  15. #define tor_evsignal_new evsignal_new
  16. #define tor_evdns_add_server_port(sock, tcp, cb, data) \
  17. evdns_add_server_port_with_base(tor_libevent_get_base(), \
  18. (sock),(tcp),(cb),(data));
  19. void tor_event_free(struct event *ev);
  20. typedef struct periodic_timer_t periodic_timer_t;
  21. periodic_timer_t *periodic_timer_new(struct event_base *base,
  22. const struct timeval *tv,
  23. void (*cb)(periodic_timer_t *timer, void *data),
  24. void *data);
  25. void periodic_timer_free(periodic_timer_t *);
  26. #define tor_event_base_loopexit event_base_loopexit
  27. /** Defines a configuration for using libevent with Tor: passed as an argument
  28. * to tor_libevent_initialize() to describe how we want to set up. */
  29. typedef struct tor_libevent_cfg {
  30. /** Flag: if true, disable IOCP (assuming that it could be enabled). */
  31. int disable_iocp;
  32. /** How many CPUs should we use (relevant only with IOCP). */
  33. int num_cpus;
  34. /** How many milliseconds should we allow between updating bandwidth limits?
  35. * (relevant only with bufferevents). */
  36. int msec_per_tick;
  37. } tor_libevent_cfg;
  38. void tor_libevent_initialize(tor_libevent_cfg *cfg);
  39. MOCK_DECL(struct event_base *, tor_libevent_get_base, (void));
  40. const char *tor_libevent_get_method(void);
  41. void tor_check_libevent_header_compatibility(void);
  42. const char *tor_libevent_get_version_str(void);
  43. const char *tor_libevent_get_header_version_str(void);
  44. #ifdef USE_BUFFEREVENTS
  45. const struct timeval *tor_libevent_get_one_tick_timeout(void);
  46. int tor_libevent_using_iocp_bufferevents(void);
  47. int tor_set_bufferevent_rate_limit(struct bufferevent *bev,
  48. struct ev_token_bucket_cfg *cfg);
  49. int tor_add_bufferevent_to_rate_limit_group(struct bufferevent *bev,
  50. struct bufferevent_rate_limit_group *g);
  51. #endif
  52. int tor_init_libevent_rng(void);
  53. void tor_gettimeofday_cached(struct timeval *tv);
  54. void tor_gettimeofday_cache_clear(void);
  55. #ifdef TOR_UNIT_TESTS
  56. void tor_gettimeofday_cache_set(const struct timeval *tv);
  57. #endif
  58. void tor_gettimeofday_cached_monotonic(struct timeval *tv);
  59. #ifdef COMPAT_LIBEVENT_PRIVATE
  60. /** Macro: returns the number of a Libevent version as a 4-byte number,
  61. with the first three bytes representing the major, minor, and patchlevel
  62. respectively of the library. The fourth byte is unused.
  63. This is equivalent to the format of LIBEVENT_VERSION_NUMBER on Libevent
  64. 2.0.1 or later. */
  65. #define V(major, minor, patch) \
  66. (((major) << 24) | ((minor) << 16) | ((patch) << 8))
  67. STATIC void
  68. libevent_logging_callback(int severity, const char *msg);
  69. #endif
  70. #endif