1*2b15cb3dSCy Schubert /* 2*2b15cb3dSCy Schubert * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu> 3*2b15cb3dSCy Schubert * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4*2b15cb3dSCy Schubert * 5*2b15cb3dSCy Schubert * Redistribution and use in source and binary forms, with or without 6*2b15cb3dSCy Schubert * modification, are permitted provided that the following conditions 7*2b15cb3dSCy Schubert * are met: 8*2b15cb3dSCy Schubert * 1. Redistributions of source code must retain the above copyright 9*2b15cb3dSCy Schubert * notice, this list of conditions and the following disclaimer. 10*2b15cb3dSCy Schubert * 2. Redistributions in binary form must reproduce the above copyright 11*2b15cb3dSCy Schubert * notice, this list of conditions and the following disclaimer in the 12*2b15cb3dSCy Schubert * documentation and/or other materials provided with the distribution. 13*2b15cb3dSCy Schubert * 3. The name of the author may not be used to endorse or promote products 14*2b15cb3dSCy Schubert * derived from this software without specific prior written permission. 15*2b15cb3dSCy Schubert * 16*2b15cb3dSCy Schubert * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17*2b15cb3dSCy Schubert * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18*2b15cb3dSCy Schubert * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19*2b15cb3dSCy Schubert * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20*2b15cb3dSCy Schubert * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21*2b15cb3dSCy Schubert * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22*2b15cb3dSCy Schubert * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23*2b15cb3dSCy Schubert * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24*2b15cb3dSCy Schubert * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25*2b15cb3dSCy Schubert * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26*2b15cb3dSCy Schubert */ 27*2b15cb3dSCy Schubert #ifndef EVENT2_EVENT_STRUCT_H_INCLUDED_ 28*2b15cb3dSCy Schubert #define EVENT2_EVENT_STRUCT_H_INCLUDED_ 29*2b15cb3dSCy Schubert 30*2b15cb3dSCy Schubert /** @file event2/event_struct.h 31*2b15cb3dSCy Schubert 32*2b15cb3dSCy Schubert Structures used by event.h. Using these structures directly WILL harm 33*2b15cb3dSCy Schubert forward compatibility: be careful. 34*2b15cb3dSCy Schubert 35*2b15cb3dSCy Schubert No field declared in this file should be used directly in user code. Except 36*2b15cb3dSCy Schubert for historical reasons, these fields would not be exposed at all. 37*2b15cb3dSCy Schubert */ 38*2b15cb3dSCy Schubert 39*2b15cb3dSCy Schubert #ifdef __cplusplus 40*2b15cb3dSCy Schubert extern "C" { 41*2b15cb3dSCy Schubert #endif 42*2b15cb3dSCy Schubert 43*2b15cb3dSCy Schubert #include <event2/event-config.h> 44*2b15cb3dSCy Schubert #ifdef EVENT__HAVE_SYS_TYPES_H 45*2b15cb3dSCy Schubert #include <sys/types.h> 46*2b15cb3dSCy Schubert #endif 47*2b15cb3dSCy Schubert #ifdef EVENT__HAVE_SYS_TIME_H 48*2b15cb3dSCy Schubert #include <sys/time.h> 49*2b15cb3dSCy Schubert #endif 50*2b15cb3dSCy Schubert 51*2b15cb3dSCy Schubert /* For int types. */ 52*2b15cb3dSCy Schubert #include <event2/util.h> 53*2b15cb3dSCy Schubert 54*2b15cb3dSCy Schubert /* For evkeyvalq */ 55*2b15cb3dSCy Schubert #include <event2/keyvalq_struct.h> 56*2b15cb3dSCy Schubert 57*2b15cb3dSCy Schubert #define EVLIST_TIMEOUT 0x01 58*2b15cb3dSCy Schubert #define EVLIST_INSERTED 0x02 59*2b15cb3dSCy Schubert #define EVLIST_SIGNAL 0x04 60*2b15cb3dSCy Schubert #define EVLIST_ACTIVE 0x08 61*2b15cb3dSCy Schubert #define EVLIST_INTERNAL 0x10 62*2b15cb3dSCy Schubert #define EVLIST_ACTIVE_LATER 0x20 63*2b15cb3dSCy Schubert #define EVLIST_FINALIZING 0x40 64*2b15cb3dSCy Schubert #define EVLIST_INIT 0x80 65*2b15cb3dSCy Schubert 66*2b15cb3dSCy Schubert #define EVLIST_ALL 0xff 67*2b15cb3dSCy Schubert 68*2b15cb3dSCy Schubert /* Fix so that people don't have to run with <sys/queue.h> */ 69*2b15cb3dSCy Schubert #ifndef TAILQ_ENTRY 70*2b15cb3dSCy Schubert #define EVENT_DEFINED_TQENTRY_ 71*2b15cb3dSCy Schubert #define TAILQ_ENTRY(type) \ 72*2b15cb3dSCy Schubert struct { \ 73*2b15cb3dSCy Schubert struct type *tqe_next; /* next element */ \ 74*2b15cb3dSCy Schubert struct type **tqe_prev; /* address of previous next element */ \ 75*2b15cb3dSCy Schubert } 76*2b15cb3dSCy Schubert #endif /* !TAILQ_ENTRY */ 77*2b15cb3dSCy Schubert 78*2b15cb3dSCy Schubert #ifndef TAILQ_HEAD 79*2b15cb3dSCy Schubert #define EVENT_DEFINED_TQHEAD_ 80*2b15cb3dSCy Schubert #define TAILQ_HEAD(name, type) \ 81*2b15cb3dSCy Schubert struct name { \ 82*2b15cb3dSCy Schubert struct type *tqh_first; \ 83*2b15cb3dSCy Schubert struct type **tqh_last; \ 84*2b15cb3dSCy Schubert } 85*2b15cb3dSCy Schubert #endif 86*2b15cb3dSCy Schubert 87*2b15cb3dSCy Schubert /* Fix so that people don't have to run with <sys/queue.h> */ 88*2b15cb3dSCy Schubert #ifndef LIST_ENTRY 89*2b15cb3dSCy Schubert #define EVENT_DEFINED_LISTENTRY_ 90*2b15cb3dSCy Schubert #define LIST_ENTRY(type) \ 91*2b15cb3dSCy Schubert struct { \ 92*2b15cb3dSCy Schubert struct type *le_next; /* next element */ \ 93*2b15cb3dSCy Schubert struct type **le_prev; /* address of previous next element */ \ 94*2b15cb3dSCy Schubert } 95*2b15cb3dSCy Schubert #endif /* !LIST_ENTRY */ 96*2b15cb3dSCy Schubert 97*2b15cb3dSCy Schubert #ifndef LIST_HEAD 98*2b15cb3dSCy Schubert #define EVENT_DEFINED_LISTHEAD_ 99*2b15cb3dSCy Schubert #define LIST_HEAD(name, type) \ 100*2b15cb3dSCy Schubert struct name { \ 101*2b15cb3dSCy Schubert struct type *lh_first; /* first element */ \ 102*2b15cb3dSCy Schubert } 103*2b15cb3dSCy Schubert #endif /* !LIST_HEAD */ 104*2b15cb3dSCy Schubert 105*2b15cb3dSCy Schubert struct event; 106*2b15cb3dSCy Schubert 107*2b15cb3dSCy Schubert struct event_callback { 108*2b15cb3dSCy Schubert TAILQ_ENTRY(event_callback) evcb_active_next; 109*2b15cb3dSCy Schubert short evcb_flags; 110*2b15cb3dSCy Schubert ev_uint8_t evcb_pri; /* smaller numbers are higher priority */ 111*2b15cb3dSCy Schubert ev_uint8_t evcb_closure; 112*2b15cb3dSCy Schubert /* allows us to adopt for different types of events */ 113*2b15cb3dSCy Schubert union { 114*2b15cb3dSCy Schubert void (*evcb_callback)(evutil_socket_t, short, void *); 115*2b15cb3dSCy Schubert void (*evcb_selfcb)(struct event_callback *, void *); 116*2b15cb3dSCy Schubert void (*evcb_evfinalize)(struct event *, void *); 117*2b15cb3dSCy Schubert void (*evcb_cbfinalize)(struct event_callback *, void *); 118*2b15cb3dSCy Schubert } evcb_cb_union; 119*2b15cb3dSCy Schubert void *evcb_arg; 120*2b15cb3dSCy Schubert }; 121*2b15cb3dSCy Schubert 122*2b15cb3dSCy Schubert struct event_base; 123*2b15cb3dSCy Schubert struct event { 124*2b15cb3dSCy Schubert struct event_callback ev_evcallback; 125*2b15cb3dSCy Schubert 126*2b15cb3dSCy Schubert /* for managing timeouts */ 127*2b15cb3dSCy Schubert union { 128*2b15cb3dSCy Schubert TAILQ_ENTRY(event) ev_next_with_common_timeout; 129*2b15cb3dSCy Schubert int min_heap_idx; 130*2b15cb3dSCy Schubert } ev_timeout_pos; 131*2b15cb3dSCy Schubert evutil_socket_t ev_fd; 132*2b15cb3dSCy Schubert 133*2b15cb3dSCy Schubert struct event_base *ev_base; 134*2b15cb3dSCy Schubert 135*2b15cb3dSCy Schubert union { 136*2b15cb3dSCy Schubert /* used for io events */ 137*2b15cb3dSCy Schubert struct { 138*2b15cb3dSCy Schubert LIST_ENTRY (event) ev_io_next; 139*2b15cb3dSCy Schubert struct timeval ev_timeout; 140*2b15cb3dSCy Schubert } ev_io; 141*2b15cb3dSCy Schubert 142*2b15cb3dSCy Schubert /* used by signal events */ 143*2b15cb3dSCy Schubert struct { 144*2b15cb3dSCy Schubert LIST_ENTRY (event) ev_signal_next; 145*2b15cb3dSCy Schubert short ev_ncalls; 146*2b15cb3dSCy Schubert /* Allows deletes in callback */ 147*2b15cb3dSCy Schubert short *ev_pncalls; 148*2b15cb3dSCy Schubert } ev_signal; 149*2b15cb3dSCy Schubert } ev_; 150*2b15cb3dSCy Schubert 151*2b15cb3dSCy Schubert short ev_events; 152*2b15cb3dSCy Schubert short ev_res; /* result passed to event callback */ 153*2b15cb3dSCy Schubert struct timeval ev_timeout; 154*2b15cb3dSCy Schubert }; 155*2b15cb3dSCy Schubert 156*2b15cb3dSCy Schubert TAILQ_HEAD (event_list, event); 157*2b15cb3dSCy Schubert 158*2b15cb3dSCy Schubert #ifdef EVENT_DEFINED_TQENTRY_ 159*2b15cb3dSCy Schubert #undef TAILQ_ENTRY 160*2b15cb3dSCy Schubert #endif 161*2b15cb3dSCy Schubert 162*2b15cb3dSCy Schubert #ifdef EVENT_DEFINED_TQHEAD_ 163*2b15cb3dSCy Schubert #undef TAILQ_HEAD 164*2b15cb3dSCy Schubert #endif 165*2b15cb3dSCy Schubert 166*2b15cb3dSCy Schubert LIST_HEAD (event_dlist, event); 167*2b15cb3dSCy Schubert 168*2b15cb3dSCy Schubert #ifdef EVENT_DEFINED_LISTENTRY_ 169*2b15cb3dSCy Schubert #undef LIST_ENTRY 170*2b15cb3dSCy Schubert #endif 171*2b15cb3dSCy Schubert 172*2b15cb3dSCy Schubert #ifdef EVENT_DEFINED_LISTHEAD_ 173*2b15cb3dSCy Schubert #undef LIST_HEAD 174*2b15cb3dSCy Schubert #endif 175*2b15cb3dSCy Schubert 176*2b15cb3dSCy Schubert #ifdef __cplusplus 177*2b15cb3dSCy Schubert } 178*2b15cb3dSCy Schubert #endif 179*2b15cb3dSCy Schubert 180*2b15cb3dSCy Schubert #endif /* EVENT2_EVENT_STRUCT_H_INCLUDED_ */ 181