compat_libevent.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. 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. /** How many CPUs should we use (not currently useful). */
  28. int num_cpus;
  29. /** How many milliseconds should we allow between updating bandwidth limits?
  30. * (Not currently useful). */
  31. int msec_per_tick;
  32. } tor_libevent_cfg;
  33. void tor_libevent_initialize(tor_libevent_cfg *cfg);
  34. MOCK_DECL(struct event_base *, tor_libevent_get_base, (void));
  35. const char *tor_libevent_get_method(void);
  36. void tor_check_libevent_header_compatibility(void);
  37. const char *tor_libevent_get_version_str(void);
  38. const char *tor_libevent_get_header_version_str(void);
  39. int tor_init_libevent_rng(void);
  40. void tor_gettimeofday_cached(struct timeval *tv);
  41. void tor_gettimeofday_cache_clear(void);
  42. #ifdef TOR_UNIT_TESTS
  43. void tor_gettimeofday_cache_set(const struct timeval *tv);
  44. void tor_libevent_postfork(void);
  45. #endif
  46. #ifdef COMPAT_LIBEVENT_PRIVATE
  47. /** Macro: returns the number of a Libevent version as a 4-byte number,
  48. with the first three bytes representing the major, minor, and patchlevel
  49. respectively of the library. The fourth byte is unused.
  50. This is equivalent to the format of LIBEVENT_VERSION_NUMBER on Libevent
  51. 2.0.1 or later. */
  52. #define V(major, minor, patch) \
  53. (((major) << 24) | ((minor) << 16) | ((patch) << 8))
  54. STATIC void
  55. libevent_logging_callback(int severity, const char *msg);
  56. #endif /* defined(COMPAT_LIBEVENT_PRIVATE) */
  57. #endif /* !defined(TOR_COMPAT_LIBEVENT_H) */