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