compat_libevent.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* Copyright (c) 2009-2017, 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. void configure_libevent_logging(void);
  8. void suppress_libevent_log_msg(const char *msg);
  9. #define tor_event_new event_new
  10. #define tor_evtimer_new evtimer_new
  11. #define tor_evsignal_new evsignal_new
  12. #define tor_evdns_add_server_port(sock, tcp, cb, data) \
  13. evdns_add_server_port_with_base(tor_libevent_get_base(), \
  14. (sock),(tcp),(cb),(data));
  15. struct event;
  16. struct event_base;
  17. void tor_event_free_(struct event *ev);
  18. #define tor_event_free(ev) \
  19. FREE_AND_NULL(struct event, tor_event_free_, (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 periodic_timer_free(t) \
  27. FREE_AND_NULL(periodic_timer_t, periodic_timer_free_, (t))
  28. #define tor_event_base_loopexit event_base_loopexit
  29. #define tor_event_base_loopbreak event_base_loopbreak
  30. /** Defines a configuration for using libevent with Tor: passed as an argument
  31. * to tor_libevent_initialize() to describe how we want to set up. */
  32. typedef struct tor_libevent_cfg {
  33. /** How many CPUs should we use (not currently useful). */
  34. int num_cpus;
  35. /** How many milliseconds should we allow between updating bandwidth limits?
  36. * (Not currently useful). */
  37. int msec_per_tick;
  38. } tor_libevent_cfg;
  39. void tor_libevent_initialize(tor_libevent_cfg *cfg);
  40. MOCK_DECL(struct event_base *, tor_libevent_get_base, (void));
  41. const char *tor_libevent_get_method(void);
  42. void tor_check_libevent_header_compatibility(void);
  43. const char *tor_libevent_get_version_str(void);
  44. const char *tor_libevent_get_header_version_str(void);
  45. void tor_libevent_free_all(void);
  46. int tor_init_libevent_rng(void);
  47. void tor_gettimeofday_cached(struct timeval *tv);
  48. void tor_gettimeofday_cache_clear(void);
  49. #ifdef TOR_UNIT_TESTS
  50. void tor_gettimeofday_cache_set(const struct timeval *tv);
  51. void tor_libevent_postfork(void);
  52. #endif
  53. #ifdef COMPAT_LIBEVENT_PRIVATE
  54. /** Macro: returns the number of a Libevent version as a 4-byte number,
  55. with the first three bytes representing the major, minor, and patchlevel
  56. respectively of the library. The fourth byte is unused.
  57. This is equivalent to the format of LIBEVENT_VERSION_NUMBER on Libevent
  58. 2.0.1 or later. */
  59. #define V(major, minor, patch) \
  60. (((major) << 24) | ((minor) << 16) | ((patch) << 8))
  61. STATIC void
  62. libevent_logging_callback(int severity, const char *msg);
  63. #endif /* defined(COMPAT_LIBEVENT_PRIVATE) */
  64. #endif /* !defined(TOR_COMPAT_LIBEVENT_H) */