compat_libevent.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #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. #define tor_event_free(ev) \
  18. FREE_AND_NULL(struct event, tor_event_free_, (ev))
  19. typedef struct periodic_timer_t periodic_timer_t;
  20. periodic_timer_t *periodic_timer_new(struct event_base *base,
  21. const struct timeval *tv,
  22. void (*cb)(periodic_timer_t *timer, void *data),
  23. void *data);
  24. void periodic_timer_free_(periodic_timer_t *);
  25. #define periodic_timer_free(t) \
  26. FREE_AND_NULL(periodic_timer_t, periodic_timer_free_, (t))
  27. #define tor_event_base_loopexit event_base_loopexit
  28. #define tor_event_base_loopbreak event_base_loopbreak
  29. /** Defines a configuration for using libevent with Tor: passed as an argument
  30. * to tor_libevent_initialize() to describe how we want to set up. */
  31. typedef struct tor_libevent_cfg {
  32. /** How many CPUs should we use (not currently useful). */
  33. int num_cpus;
  34. /** How many milliseconds should we allow between updating bandwidth limits?
  35. * (Not currently useful). */
  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. int tor_init_libevent_rng(void);
  45. void tor_gettimeofday_cached(struct timeval *tv);
  46. void tor_gettimeofday_cache_clear(void);
  47. #ifdef TOR_UNIT_TESTS
  48. void tor_gettimeofday_cache_set(const struct timeval *tv);
  49. void tor_libevent_postfork(void);
  50. #endif
  51. #ifdef COMPAT_LIBEVENT_PRIVATE
  52. /** Macro: returns the number of a Libevent version as a 4-byte number,
  53. with the first three bytes representing the major, minor, and patchlevel
  54. respectively of the library. The fourth byte is unused.
  55. This is equivalent to the format of LIBEVENT_VERSION_NUMBER on Libevent
  56. 2.0.1 or later. */
  57. #define V(major, minor, patch) \
  58. (((major) << 24) | ((minor) << 16) | ((patch) << 8))
  59. STATIC void
  60. libevent_logging_callback(int severity, const char *msg);
  61. #endif /* defined(COMPAT_LIBEVENT_PRIVATE) */
  62. #endif /* !defined(TOR_COMPAT_LIBEVENT_H) */