compat_libevent.h 3.2 KB

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