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