event_compat.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
  3. * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. The name of the author may not be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  17. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  18. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  19. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  23. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  25. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #ifndef _EVENT2_EVENT_COMPAT_H_
  28. #define _EVENT2_EVENT_COMPAT_H_
  29. /** @file event2/event_compat.h
  30. Potentially non-threadsafe versions of the functions in event.h: provided
  31. only for backwards compatibility.
  32. In the oldest versions of Libevent, event_base was not a first-class
  33. structure. Instead, there was a single event base that every function
  34. manipulated. Later, when separate event bases were added, the old functions
  35. that didn't take an event_base argument needed to work by manipulating the
  36. "current" event base. This could lead to thread-safety issues, and obscure,
  37. hard-to-diagnose bugs.
  38. @deprecated All functions in this file are by definition deprecated.
  39. */
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. #include <event2/event-config.h>
  44. #ifdef _EVENT_HAVE_SYS_TYPES_H
  45. #include <sys/types.h>
  46. #endif
  47. #ifdef _EVENT_HAVE_SYS_TIME_H
  48. #include <sys/time.h>
  49. #endif
  50. /* For int types. */
  51. #include <event2/util.h>
  52. /**
  53. Initialize the event API.
  54. The event API needs to be initialized with event_init() before it can be
  55. used. Sets the global current base that gets used for events that have no
  56. base associated with them.
  57. @deprecated This function is deprecated because it replaces the "current"
  58. event_base, and is totally unsafe for multithreaded use. The replacement
  59. is event_base_new().
  60. @see event_base_set(), event_base_new()
  61. */
  62. struct event_base *event_init(void);
  63. /**
  64. Loop to process events.
  65. Like event_base_dispatch(), but uses the "current" base.
  66. @deprecated This function is deprecated because it is easily confused by
  67. multiple calls to event_init(), and because it is not safe for
  68. multithreaded use. The replacement is event_base_dispatch().
  69. @see event_base_dispatch(), event_init()
  70. */
  71. int event_dispatch(void);
  72. /**
  73. Handle events.
  74. This function behaves like event_base_loop(), but uses the "current" base
  75. @deprecated This function is deprecated because it uses the event base from
  76. the last call to event_init, and is therefore not safe for multithreaded
  77. use. The replacement is event_base_loop().
  78. @see event_base_loop(), event_init()
  79. */
  80. int event_loop(int);
  81. /**
  82. Exit the event loop after the specified time.
  83. This function behaves like event_base_loopexit(), except that it uses the
  84. "current" base.
  85. @deprecated This function is deprecated because it uses the event base from
  86. the last call to event_init, and is therefore not safe for multithreaded
  87. use. The replacement is event_base_loopexit().
  88. @see event_init, event_base_loopexit()
  89. */
  90. int event_loopexit(const struct timeval *);
  91. /**
  92. Abort the active event_loop() immediately.
  93. This function behaves like event_base_loopbreakt(), except that it uses the
  94. "current" base.
  95. @deprecated This function is deprecated because it uses the event base from
  96. the last call to event_init, and is therefore not safe for multithreaded
  97. use. The replacement is event_base_loopbreak().
  98. @see event_base_loopbreak(), event_init()
  99. */
  100. int event_loopbreak(void);
  101. /**
  102. Schedule a one-time event to occur.
  103. @deprecated This function is obsolete, and has been replaced by
  104. event_base_once(). Its use is deprecated because it relies on the
  105. "current" base configured by event_init().
  106. @see event_base_once()
  107. */
  108. int event_once(evutil_socket_t , short,
  109. void (*)(evutil_socket_t, short, void *), void *, const struct timeval *);
  110. /**
  111. Get the kernel event notification mechanism used by Libevent.
  112. @deprecated This function is obsolete, and has been replaced by
  113. event_base_get_method(). Its use is deprecated because it relies on the
  114. "current" base configured by event_init().
  115. @see event_base_get_method()
  116. */
  117. const char *event_get_method(void);
  118. /**
  119. Set the number of different event priorities.
  120. @deprecated This function is deprecated because it is easily confused by
  121. multiple calls to event_init(), and because it is not safe for
  122. multithreaded use. The replacement is event_base_priority_init().
  123. @see event_base_priority_init()
  124. */
  125. int event_priority_init(int);
  126. /**
  127. Prepare an event structure to be added.
  128. @deprecated event_set() is not recommended for new code, because it requires
  129. a subsequent call to event_base_set() to be safe under most circumstances.
  130. Use event_assign() or event_new() instead.
  131. */
  132. void event_set(struct event *, evutil_socket_t, short, void (*)(evutil_socket_t, short, void *), void *);
  133. #define evtimer_set(ev, cb, arg) event_set((ev), -1, 0, (cb), (arg))
  134. #define evsignal_set(ev, x, cb, arg) \
  135. event_set((ev), (x), EV_SIGNAL|EV_PERSIST, (cb), (arg))
  136. /**
  137. @name timeout_* macros
  138. @deprecated These macros are deprecated because their naming is inconsistent
  139. with the rest of Libevent. Use the evtimer_* macros instead.
  140. @{
  141. */
  142. #define timeout_add(ev, tv) event_add((ev), (tv))
  143. #define timeout_set(ev, cb, arg) event_set((ev), -1, 0, (cb), (arg))
  144. #define timeout_del(ev) event_del(ev)
  145. #define timeout_pending(ev, tv) event_pending((ev), EV_TIMEOUT, (tv))
  146. #define timeout_initialized(ev) event_initialized(ev)
  147. /**@}*/
  148. /**
  149. @name signal_* macros
  150. @deprecated These macros are deprecated because their naming is inconsistent
  151. with the rest of Libevent. Use the evsignal_* macros instead.
  152. @{
  153. */
  154. #define signal_add(ev, tv) event_add((ev), (tv))
  155. #define signal_set(ev, x, cb, arg) \
  156. event_set((ev), (x), EV_SIGNAL|EV_PERSIST, (cb), (arg))
  157. #define signal_del(ev) event_del(ev)
  158. #define signal_pending(ev, tv) event_pending((ev), EV_SIGNAL, (tv))
  159. #define signal_initialized(ev) event_initialized(ev)
  160. /**@}*/
  161. #ifndef EVENT_FD
  162. /* These macros are obsolete; use event_get_fd and event_get_signal instead. */
  163. #define EVENT_FD(ev) ((int)event_get_fd(ev))
  164. #define EVENT_SIGNAL(ev) event_get_signal(ev)
  165. #endif
  166. #ifdef __cplusplus
  167. }
  168. #endif
  169. #endif /* _EVENT2_EVENT_COMPAT_H_ */