1290001Sglebius/* 2290001Sglebius * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu> 3290001Sglebius * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4290001Sglebius * 5290001Sglebius * Redistribution and use in source and binary forms, with or without 6290001Sglebius * modification, are permitted provided that the following conditions 7290001Sglebius * are met: 8290001Sglebius * 1. Redistributions of source code must retain the above copyright 9290001Sglebius * notice, this list of conditions and the following disclaimer. 10290001Sglebius * 2. Redistributions in binary form must reproduce the above copyright 11290001Sglebius * notice, this list of conditions and the following disclaimer in the 12290001Sglebius * documentation and/or other materials provided with the distribution. 13290001Sglebius * 3. The name of the author may not be used to endorse or promote products 14290001Sglebius * derived from this software without specific prior written permission. 15290001Sglebius * 16290001Sglebius * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17290001Sglebius * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18290001Sglebius * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19290001Sglebius * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20290001Sglebius * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21290001Sglebius * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22290001Sglebius * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23290001Sglebius * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24290001Sglebius * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25290001Sglebius * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26290001Sglebius */ 27290001Sglebius#ifndef EVENT2_EVENT_COMPAT_H_INCLUDED_ 28290001Sglebius#define EVENT2_EVENT_COMPAT_H_INCLUDED_ 29290001Sglebius 30290001Sglebius/** @file event2/event_compat.h 31290001Sglebius 32290001Sglebius Potentially non-threadsafe versions of the functions in event.h: provided 33290001Sglebius only for backwards compatibility. 34290001Sglebius 35290001Sglebius In the oldest versions of Libevent, event_base was not a first-class 36290001Sglebius structure. Instead, there was a single event base that every function 37290001Sglebius manipulated. Later, when separate event bases were added, the old functions 38290001Sglebius that didn't take an event_base argument needed to work by manipulating the 39290001Sglebius "current" event base. This could lead to thread-safety issues, and obscure, 40290001Sglebius hard-to-diagnose bugs. 41290001Sglebius 42290001Sglebius @deprecated All functions in this file are by definition deprecated. 43290001Sglebius */ 44290001Sglebius#include <event2/visibility.h> 45290001Sglebius 46290001Sglebius#ifdef __cplusplus 47290001Sglebiusextern "C" { 48290001Sglebius#endif 49290001Sglebius 50290001Sglebius#include <event2/event-config.h> 51290001Sglebius#ifdef EVENT__HAVE_SYS_TYPES_H 52290001Sglebius#include <sys/types.h> 53290001Sglebius#endif 54290001Sglebius#ifdef EVENT__HAVE_SYS_TIME_H 55290001Sglebius#include <sys/time.h> 56290001Sglebius#endif 57290001Sglebius 58290001Sglebius/* For int types. */ 59290001Sglebius#include <event2/util.h> 60290001Sglebius 61290001Sglebius/** 62290001Sglebius Initialize the event API. 63290001Sglebius 64290001Sglebius The event API needs to be initialized with event_init() before it can be 65290001Sglebius used. Sets the global current base that gets used for events that have no 66290001Sglebius base associated with them. 67290001Sglebius 68290001Sglebius @deprecated This function is deprecated because it replaces the "current" 69290001Sglebius event_base, and is totally unsafe for multithreaded use. The replacement 70290001Sglebius is event_base_new(). 71290001Sglebius 72290001Sglebius @see event_base_set(), event_base_new() 73290001Sglebius */ 74290001SglebiusEVENT2_EXPORT_SYMBOL 75290001Sglebiusstruct event_base *event_init(void); 76290001Sglebius 77290001Sglebius/** 78290001Sglebius Loop to process events. 79290001Sglebius 80290001Sglebius Like event_base_dispatch(), but uses the "current" base. 81290001Sglebius 82290001Sglebius @deprecated This function is deprecated because it is easily confused by 83290001Sglebius multiple calls to event_init(), and because it is not safe for 84290001Sglebius multithreaded use. The replacement is event_base_dispatch(). 85290001Sglebius 86290001Sglebius @see event_base_dispatch(), event_init() 87290001Sglebius */ 88290001SglebiusEVENT2_EXPORT_SYMBOL 89290001Sglebiusint event_dispatch(void); 90290001Sglebius 91290001Sglebius/** 92290001Sglebius Handle events. 93290001Sglebius 94290001Sglebius This function behaves like event_base_loop(), but uses the "current" base 95290001Sglebius 96290001Sglebius @deprecated This function is deprecated because it uses the event base from 97290001Sglebius the last call to event_init, and is therefore not safe for multithreaded 98290001Sglebius use. The replacement is event_base_loop(). 99290001Sglebius 100290001Sglebius @see event_base_loop(), event_init() 101290001Sglebius*/ 102290001SglebiusEVENT2_EXPORT_SYMBOL 103290001Sglebiusint event_loop(int); 104290001Sglebius 105290001Sglebius 106290001Sglebius/** 107290001Sglebius Exit the event loop after the specified time. 108290001Sglebius 109290001Sglebius This function behaves like event_base_loopexit(), except that it uses the 110290001Sglebius "current" base. 111290001Sglebius 112290001Sglebius @deprecated This function is deprecated because it uses the event base from 113290001Sglebius the last call to event_init, and is therefore not safe for multithreaded 114290001Sglebius use. The replacement is event_base_loopexit(). 115290001Sglebius 116290001Sglebius @see event_init, event_base_loopexit() 117290001Sglebius */ 118290001SglebiusEVENT2_EXPORT_SYMBOL 119290001Sglebiusint event_loopexit(const struct timeval *); 120290001Sglebius 121290001Sglebius 122290001Sglebius/** 123290001Sglebius Abort the active event_loop() immediately. 124290001Sglebius 125290001Sglebius This function behaves like event_base_loopbreakt(), except that it uses the 126290001Sglebius "current" base. 127290001Sglebius 128290001Sglebius @deprecated This function is deprecated because it uses the event base from 129290001Sglebius the last call to event_init, and is therefore not safe for multithreaded 130290001Sglebius use. The replacement is event_base_loopbreak(). 131290001Sglebius 132290001Sglebius @see event_base_loopbreak(), event_init() 133290001Sglebius */ 134290001SglebiusEVENT2_EXPORT_SYMBOL 135290001Sglebiusint event_loopbreak(void); 136290001Sglebius 137290001Sglebius/** 138290001Sglebius Schedule a one-time event to occur. 139290001Sglebius 140290001Sglebius @deprecated This function is obsolete, and has been replaced by 141290001Sglebius event_base_once(). Its use is deprecated because it relies on the 142290001Sglebius "current" base configured by event_init(). 143290001Sglebius 144290001Sglebius @see event_base_once() 145290001Sglebius */ 146290001SglebiusEVENT2_EXPORT_SYMBOL 147290001Sglebiusint event_once(evutil_socket_t , short, 148290001Sglebius void (*)(evutil_socket_t, short, void *), void *, const struct timeval *); 149290001Sglebius 150290001Sglebius 151290001Sglebius/** 152290001Sglebius Get the kernel event notification mechanism used by Libevent. 153290001Sglebius 154290001Sglebius @deprecated This function is obsolete, and has been replaced by 155290001Sglebius event_base_get_method(). Its use is deprecated because it relies on the 156290001Sglebius "current" base configured by event_init(). 157290001Sglebius 158290001Sglebius @see event_base_get_method() 159290001Sglebius */ 160290001SglebiusEVENT2_EXPORT_SYMBOL 161290001Sglebiusconst char *event_get_method(void); 162290001Sglebius 163290001Sglebius 164290001Sglebius/** 165290001Sglebius Set the number of different event priorities. 166290001Sglebius 167290001Sglebius @deprecated This function is deprecated because it is easily confused by 168290001Sglebius multiple calls to event_init(), and because it is not safe for 169290001Sglebius multithreaded use. The replacement is event_base_priority_init(). 170290001Sglebius 171290001Sglebius @see event_base_priority_init() 172290001Sglebius */ 173290001SglebiusEVENT2_EXPORT_SYMBOL 174290001Sglebiusint event_priority_init(int); 175290001Sglebius 176290001Sglebius/** 177290001Sglebius Prepare an event structure to be added. 178290001Sglebius 179290001Sglebius @deprecated event_set() is not recommended for new code, because it requires 180290001Sglebius a subsequent call to event_base_set() to be safe under most circumstances. 181290001Sglebius Use event_assign() or event_new() instead. 182290001Sglebius */ 183290001SglebiusEVENT2_EXPORT_SYMBOL 184290001Sglebiusvoid event_set(struct event *, evutil_socket_t, short, void (*)(evutil_socket_t, short, void *), void *); 185290001Sglebius 186290001Sglebius#define evtimer_set(ev, cb, arg) event_set((ev), -1, 0, (cb), (arg)) 187290001Sglebius#define evsignal_set(ev, x, cb, arg) \ 188290001Sglebius event_set((ev), (x), EV_SIGNAL|EV_PERSIST, (cb), (arg)) 189290001Sglebius 190290001Sglebius 191290001Sglebius/** 192290001Sglebius @name timeout_* macros 193290001Sglebius 194290001Sglebius @deprecated These macros are deprecated because their naming is inconsistent 195290001Sglebius with the rest of Libevent. Use the evtimer_* macros instead. 196290001Sglebius @{ 197290001Sglebius */ 198290001Sglebius#define timeout_add(ev, tv) event_add((ev), (tv)) 199290001Sglebius#define timeout_set(ev, cb, arg) event_set((ev), -1, 0, (cb), (arg)) 200290001Sglebius#define timeout_del(ev) event_del(ev) 201290001Sglebius#define timeout_pending(ev, tv) event_pending((ev), EV_TIMEOUT, (tv)) 202290001Sglebius#define timeout_initialized(ev) event_initialized(ev) 203290001Sglebius/**@}*/ 204290001Sglebius 205290001Sglebius/** 206290001Sglebius @name signal_* macros 207290001Sglebius 208290001Sglebius @deprecated These macros are deprecated because their naming is inconsistent 209290001Sglebius with the rest of Libevent. Use the evsignal_* macros instead. 210290001Sglebius @{ 211290001Sglebius */ 212290001Sglebius#define signal_add(ev, tv) event_add((ev), (tv)) 213290001Sglebius#define signal_set(ev, x, cb, arg) \ 214290001Sglebius event_set((ev), (x), EV_SIGNAL|EV_PERSIST, (cb), (arg)) 215290001Sglebius#define signal_del(ev) event_del(ev) 216290001Sglebius#define signal_pending(ev, tv) event_pending((ev), EV_SIGNAL, (tv)) 217290001Sglebius#define signal_initialized(ev) event_initialized(ev) 218290001Sglebius/**@}*/ 219290001Sglebius 220290001Sglebius#ifndef EVENT_FD 221290001Sglebius/* These macros are obsolete; use event_get_fd and event_get_signal instead. */ 222290001Sglebius#define EVENT_FD(ev) ((int)event_get_fd(ev)) 223290001Sglebius#define EVENT_SIGNAL(ev) event_get_signal(ev) 224290001Sglebius#endif 225290001Sglebius 226290001Sglebius#ifdef __cplusplus 227290001Sglebius} 228290001Sglebius#endif 229290001Sglebius 230290001Sglebius#endif /* EVENT2_EVENT_COMPAT_H_INCLUDED_ */ 231