compat_libevent.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* Copyright (c) 2009, 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. struct event;
  7. struct event_base;
  8. #ifdef USE_BUFFEREVENTS
  9. struct bufferevent;
  10. #endif
  11. #ifdef HAVE_EVENT2_EVENT_H
  12. #include <event2/util.h>
  13. #elif !defined(EVUTIL_SOCKET_DEFINED)
  14. #define EVUTIL_SOCKET_DEFINED
  15. #define evutil_socket_t int
  16. #endif
  17. void configure_libevent_logging(void);
  18. void suppress_libevent_log_msg(const char *msg);
  19. #ifdef HAVE_EVENT2_EVENT_H
  20. #define tor_event_new event_new
  21. #define tor_evtimer_new evtimer_new
  22. #define tor_evsignal_new evsignal_new
  23. #define tor_event_free event_free
  24. #define tor_evdns_add_server_port(sock, tcp, cb, data) \
  25. evdns_add_server_port_with_base(tor_libevent_get_base(), \
  26. (sock),(tcp),(cb),(data));
  27. #else
  28. struct event *tor_event_new(struct event_base * base, evutil_socket_t sock,
  29. short what, void (*cb)(evutil_socket_t, short, void *), void *arg);
  30. struct event *tor_evtimer_new(struct event_base * base,
  31. void (*cb)(evutil_socket_t, short, void *), void *arg);
  32. struct event *tor_evsignal_new(struct event_base * base, int sig,
  33. void (*cb)(evutil_socket_t, short, void *), void *arg);
  34. void tor_event_free(struct event *ev);
  35. #define tor_evdns_add_server_port evdns_add_server_port
  36. #endif
  37. typedef struct periodic_timer_t periodic_timer_t;
  38. periodic_timer_t *periodic_timer_new(struct event_base *base,
  39. const struct timeval *tv,
  40. void (*cb)(periodic_timer_t *timer, void *data),
  41. void *data);
  42. void periodic_timer_free(periodic_timer_t *);
  43. #ifdef HAVE_EVENT_BASE_LOOPEXIT
  44. #define tor_event_base_loopexit event_base_loopexit
  45. #else
  46. struct timeval;
  47. int tor_event_base_loopexit(struct event_base *base, struct timeval *tv);
  48. #endif
  49. typedef struct tor_libevent_cfg {
  50. int disable_iocp;
  51. int num_cpus;
  52. } tor_libevent_cfg;
  53. void tor_libevent_initialize(tor_libevent_cfg *cfg);
  54. struct event_base *tor_libevent_get_base(void);
  55. const char *tor_libevent_get_method(void);
  56. void tor_check_libevent_version(const char *m, int server,
  57. const char **badness_out);
  58. void tor_check_libevent_header_compatibility(void);
  59. const char *tor_libevent_get_version_str(void);
  60. #ifdef USE_BUFFEREVENTS
  61. #define TOR_LIBEVENT_TICKS_PER_SECOND 3
  62. const struct timeval *tor_libevent_get_one_tick_timeout(void);
  63. #endif
  64. #endif