xref: /freebsd/contrib/libevent/include/event2/event_compat.h (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
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 
30 /** @file event2/event_compat.h
31 
32   Potentially non-threadsafe versions of the functions in event.h: provided
33   only for backwards compatibility.
34 
35   In the oldest versions of Libevent, event_base was not a first-class
36   structure.  Instead, there was a single event base that every function
37   manipulated.  Later, when separate event bases were added, the old functions
38   that didn't take an event_base argument needed to work by manipulating the
39   "current" event base.  This could lead to thread-safety issues, and obscure,
40   hard-to-diagnose bugs.
41 
42   @deprecated All functions in this file are by definition deprecated.
43  */
44 #include <event2/visibility.h>
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 #include <event2/event-config.h>
51 #ifdef EVENT__HAVE_SYS_TYPES_H
52 #include <sys/types.h>
53 #endif
54 #ifdef EVENT__HAVE_SYS_TIME_H
55 #include <sys/time.h>
56 #endif
57 
58 /* For int types. */
59 #include <event2/util.h>
60 
61 /**
62   Initialize the event API.
63 
64   The event API needs to be initialized with event_init() before it can be
65   used.  Sets the global current base that gets used for events that have no
66   base associated with them.
67 
68   @deprecated This function is deprecated because it replaces the "current"
69     event_base, and is totally unsafe for multithreaded use.  The replacement
70     is event_base_new().
71 
72   @see event_base_set(), event_base_new()
73  */
74 EVENT2_EXPORT_SYMBOL
75 struct event_base *event_init(void);
76 
77 /**
78   Loop to process events.
79 
80   Like event_base_dispatch(), but uses the "current" base.
81 
82   @deprecated This function is deprecated because it is easily confused by
83     multiple calls to event_init(), and because it is not safe for
84     multithreaded use.  The replacement is event_base_dispatch().
85 
86   @see event_base_dispatch(), event_init()
87  */
88 EVENT2_EXPORT_SYMBOL
89 int event_dispatch(void);
90 
91 /**
92   Handle events.
93 
94   This function behaves like event_base_loop(), but uses the "current" base
95 
96   @deprecated This function is deprecated because it uses the event base from
97     the last call to event_init, and is therefore not safe for multithreaded
98     use.  The replacement is event_base_loop().
99 
100   @see event_base_loop(), event_init()
101 */
102 EVENT2_EXPORT_SYMBOL
103 int event_loop(int);
104 
105 
106 /**
107   Exit the event loop after the specified time.
108 
109   This function behaves like event_base_loopexit(), except that it uses the
110   "current" base.
111 
112   @deprecated This function is deprecated because it uses the event base from
113     the last call to event_init, and is therefore not safe for multithreaded
114     use.  The replacement is event_base_loopexit().
115 
116   @see event_init, event_base_loopexit()
117   */
118 EVENT2_EXPORT_SYMBOL
119 int event_loopexit(const struct timeval *);
120 
121 
122 /**
123   Abort the active event_loop() immediately.
124 
125   This function behaves like event_base_loopbreakt(), except that it uses the
126   "current" base.
127 
128   @deprecated This function is deprecated because it uses the event base from
129     the last call to event_init, and is therefore not safe for multithreaded
130     use.  The replacement is event_base_loopbreak().
131 
132   @see event_base_loopbreak(), event_init()
133  */
134 EVENT2_EXPORT_SYMBOL
135 int event_loopbreak(void);
136 
137 /**
138   Schedule a one-time event to occur.
139 
140   @deprecated This function is obsolete, and has been replaced by
141     event_base_once(). Its use is deprecated because it relies on the
142     "current" base configured by event_init().
143 
144   @see event_base_once()
145  */
146 EVENT2_EXPORT_SYMBOL
147 int event_once(evutil_socket_t , short,
148     void (*)(evutil_socket_t, short, void *), void *, const struct timeval *);
149 
150 
151 /**
152   Get the kernel event notification mechanism used by Libevent.
153 
154   @deprecated This function is obsolete, and has been replaced by
155     event_base_get_method(). Its use is deprecated because it relies on the
156     "current" base configured by event_init().
157 
158   @see event_base_get_method()
159  */
160 EVENT2_EXPORT_SYMBOL
161 const char *event_get_method(void);
162 
163 
164 /**
165   Set the number of different event priorities.
166 
167   @deprecated This function is deprecated because it is easily confused by
168     multiple calls to event_init(), and because it is not safe for
169     multithreaded use.  The replacement is event_base_priority_init().
170 
171   @see event_base_priority_init()
172  */
173 EVENT2_EXPORT_SYMBOL
174 int	event_priority_init(int);
175 
176 /**
177   Prepare an event structure to be added.
178 
179   @deprecated event_set() is not recommended for new code, because it requires
180      a subsequent call to event_base_set() to be safe under most circumstances.
181      Use event_assign() or event_new() instead.
182  */
183 EVENT2_EXPORT_SYMBOL
184 void event_set(struct event *, evutil_socket_t, short, void (*)(evutil_socket_t, short, void *), void *);
185 
186 #define evtimer_set(ev, cb, arg)	event_set((ev), -1, 0, (cb), (arg))
187 #define evsignal_set(ev, x, cb, arg)	\
188 	event_set((ev), (x), EV_SIGNAL|EV_PERSIST, (cb), (arg))
189 
190 
191 /**
192    @name timeout_* macros
193 
194    @deprecated These macros are deprecated because their naming is inconsistent
195      with the rest of Libevent.  Use the evtimer_* macros instead.
196    @{
197  */
198 #define timeout_add(ev, tv)		event_add((ev), (tv))
199 #define timeout_set(ev, cb, arg)	event_set((ev), -1, 0, (cb), (arg))
200 #define timeout_del(ev)			event_del(ev)
201 #define timeout_pending(ev, tv)		event_pending((ev), EV_TIMEOUT, (tv))
202 #define timeout_initialized(ev)		event_initialized(ev)
203 /**@}*/
204 
205 /**
206    @name signal_* macros
207 
208    @deprecated These macros are deprecated because their naming is inconsistent
209      with the rest of Libevent.  Use the evsignal_* macros instead.
210    @{
211  */
212 #define signal_add(ev, tv)		event_add((ev), (tv))
213 #define signal_set(ev, x, cb, arg)				\
214 	event_set((ev), (x), EV_SIGNAL|EV_PERSIST, (cb), (arg))
215 #define signal_del(ev)			event_del(ev)
216 #define signal_pending(ev, tv)		event_pending((ev), EV_SIGNAL, (tv))
217 #define signal_initialized(ev)		event_initialized(ev)
218 /**@}*/
219 
220 #ifndef EVENT_FD
221 /* These macros are obsolete; use event_get_fd and event_get_signal instead. */
222 #define EVENT_FD(ev)		((int)event_get_fd(ev))
223 #define EVENT_SIGNAL(ev)	event_get_signal(ev)
224 #endif
225 
226 #ifdef __cplusplus
227 }
228 #endif
229 
230 #endif /* EVENT2_EVENT_COMPAT_H_INCLUDED_ */
231