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