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