compat_libevent.h 2.5 KB

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