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