event_compat.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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_INCLUDED_
  28. #define EVENT2_EVENT_COMPAT_H_INCLUDED_
  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. #include <event2/visibility.h>
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. #include <event2/event-config.h>
  45. #ifdef EVENT__HAVE_SYS_TYPES_H
  46. #include <sys/types.h>
  47. #endif
  48. #ifdef EVENT__HAVE_SYS_TIME_H
  49. #include <sys/time.h>
  50. #endif
  51. /* For int types. */
  52. #include <event2/util.h>
  53. /**
  54. Initialize the event API.
  55. The event API needs to be initialized with event_init() before it can be
  56. used. Sets the global current base that gets used for events that have no
  57. base associated with them.
  58. @deprecated This function is deprecated because it replaces the "current"
  59. event_base, and is totally unsafe for multithreaded use. The replacement
  60. is event_base_new().
  61. @see event_base_set(), event_base_new()
  62. */
  63. EVENT2_EXPORT_SYMBOL
  64. struct event_base *event_init(void);
  65. /**
  66. Loop to process events.
  67. Like event_base_dispatch(), but uses the "current" base.
  68. @deprecated This function is deprecated because it is easily confused by
  69. multiple calls to event_init(), and because it is not safe for
  70. multithreaded use. The replacement is event_base_dispatch().
  71. @see event_base_dispatch(), event_init()
  72. */
  73. EVENT2_EXPORT_SYMBOL
  74. int event_dispatch(void);
  75. /**
  76. Handle events.
  77. This function behaves like event_base_loop(), but uses the "current" base
  78. @deprecated This function is deprecated because it uses the event base from
  79. the last call to event_init, and is therefore not safe for multithreaded
  80. use. The replacement is event_base_loop().
  81. @see event_base_loop(), event_init()
  82. */
  83. EVENT2_EXPORT_SYMBOL
  84. int event_loop(int);
  85. /**
  86. Exit the event loop after the specified time.
  87. This function behaves like event_base_loopexit(), except that it uses the
  88. "current" base.
  89. @deprecated This function is deprecated because it uses the event base from
  90. the last call to event_init, and is therefore not safe for multithreaded
  91. use. The replacement is event_base_loopexit().
  92. @see event_init, event_base_loopexit()
  93. */
  94. EVENT2_EXPORT_SYMBOL
  95. int event_loopexit(const struct timeval *);
  96. /**
  97. Abort the active event_loop() immediately.
  98. This function behaves like event_base_loopbreakt(), except that it uses the
  99. "current" base.
  100. @deprecated This function is deprecated because it uses the event base from
  101. the last call to event_init, and is therefore not safe for multithreaded
  102. use. The replacement is event_base_loopbreak().
  103. @see event_base_loopbreak(), event_init()
  104. */
  105. EVENT2_EXPORT_SYMBOL
  106. int event_loopbreak(void);
  107. /**
  108. Schedule a one-time event to occur.
  109. @deprecated This function is obsolete, and has been replaced by
  110. event_base_once(). Its use is deprecated because it relies on the
  111. "current" base configured by event_init().
  112. @see event_base_once()
  113. */
  114. EVENT2_EXPORT_SYMBOL
  115. int event_once(evutil_socket_t , short,
  116. void (*)(evutil_socket_t, short, void *), void *, const struct timeval *);
  117. /**
  118. Get the kernel event notification mechanism used by Libevent.
  119. @deprecated This function is obsolete, and has been replaced by
  120. event_base_get_method(). Its use is deprecated because it relies on the
  121. "current" base configured by event_init().
  122. @see event_base_get_method()
  123. */
  124. EVENT2_EXPORT_SYMBOL
  125. const char *event_get_method(void);
  126. /**
  127. Set the number of different event priorities.
  128. @deprecated This function is deprecated because it is easily confused by
  129. multiple calls to event_init(), and because it is not safe for
  130. multithreaded use. The replacement is event_base_priority_init().
  131. @see event_base_priority_init()
  132. */
  133. EVENT2_EXPORT_SYMBOL
  134. int event_priority_init(int);
  135. /**
  136. Prepare an event structure to be added.
  137. @deprecated event_set() is not recommended for new code, because it requires
  138. a subsequent call to event_base_set() to be safe under most circumstances.
  139. Use event_assign() or event_new() instead.
  140. */
  141. EVENT2_EXPORT_SYMBOL
  142. void event_set(struct event *, evutil_socket_t, short, void (*)(evutil_socket_t, short, void *), void *);
  143. #define evtimer_set(ev, cb, arg) event_set((ev), -1, 0, (cb), (arg))
  144. #define evsignal_set(ev, x, cb, arg) \
  145. event_set((ev), (x), EV_SIGNAL|EV_PERSIST, (cb), (arg))
  146. /**
  147. @name timeout_* macros
  148. @deprecated These macros are deprecated because their naming is inconsistent
  149. with the rest of Libevent. Use the evtimer_* macros instead.
  150. @{
  151. */
  152. #define timeout_add(ev, tv) event_add((ev), (tv))
  153. #define timeout_set(ev, cb, arg) event_set((ev), -1, 0, (cb), (arg))
  154. #define timeout_del(ev) event_del(ev)
  155. #define timeout_pending(ev, tv) event_pending((ev), EV_TIMEOUT, (tv))
  156. #define timeout_initialized(ev) event_initialized(ev)
  157. /**@}*/
  158. /**
  159. @name signal_* macros
  160. @deprecated These macros are deprecated because their naming is inconsistent
  161. with the rest of Libevent. Use the evsignal_* macros instead.
  162. @{
  163. */
  164. #define signal_add(ev, tv) event_add((ev), (tv))
  165. #define signal_set(ev, x, cb, arg) \
  166. event_set((ev), (x), EV_SIGNAL|EV_PERSIST, (cb), (arg))
  167. #define signal_del(ev) event_del(ev)
  168. #define signal_pending(ev, tv) event_pending((ev), EV_SIGNAL, (tv))
  169. #define signal_initialized(ev) event_initialized(ev)
  170. /**@}*/
  171. #ifndef EVENT_FD
  172. /* These macros are obsolete; use event_get_fd and event_get_signal instead. */
  173. #define EVENT_FD(ev) ((int)event_get_fd(ev))
  174. #define EVENT_SIGNAL(ev) event_get_signal(ev)
  175. #endif
  176. #ifdef __cplusplus
  177. }
  178. #endif
  179. #endif /* EVENT2_EVENT_COMPAT_H_INCLUDED_ */