compat_libevent.h 2.3 KB

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