1*40f5f2eeSchristos /* $NetBSD: event_struct.h,v 1.1.1.3 2017/01/31 21:14:53 christos Exp $ */ 293dcc084Schristos /* 393dcc084Schristos * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu> 493dcc084Schristos * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 593dcc084Schristos * 693dcc084Schristos * Redistribution and use in source and binary forms, with or without 793dcc084Schristos * modification, are permitted provided that the following conditions 893dcc084Schristos * are met: 993dcc084Schristos * 1. Redistributions of source code must retain the above copyright 1093dcc084Schristos * notice, this list of conditions and the following disclaimer. 1193dcc084Schristos * 2. Redistributions in binary form must reproduce the above copyright 1293dcc084Schristos * notice, this list of conditions and the following disclaimer in the 1393dcc084Schristos * documentation and/or other materials provided with the distribution. 1493dcc084Schristos * 3. The name of the author may not be used to endorse or promote products 1593dcc084Schristos * derived from this software without specific prior written permission. 1693dcc084Schristos * 1793dcc084Schristos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1893dcc084Schristos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1993dcc084Schristos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2093dcc084Schristos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2193dcc084Schristos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2293dcc084Schristos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2393dcc084Schristos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2493dcc084Schristos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2593dcc084Schristos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2693dcc084Schristos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2793dcc084Schristos */ 28*40f5f2eeSchristos #ifndef EVENT2_EVENT_STRUCT_H_INCLUDED_ 29*40f5f2eeSchristos #define EVENT2_EVENT_STRUCT_H_INCLUDED_ 3093dcc084Schristos 3193dcc084Schristos /** @file event2/event_struct.h 3293dcc084Schristos 3393dcc084Schristos Structures used by event.h. Using these structures directly WILL harm 3493dcc084Schristos forward compatibility: be careful. 3593dcc084Schristos 3693dcc084Schristos No field declared in this file should be used directly in user code. Except 3793dcc084Schristos for historical reasons, these fields would not be exposed at all. 3893dcc084Schristos */ 3993dcc084Schristos 4093dcc084Schristos #ifdef __cplusplus 4193dcc084Schristos extern "C" { 4293dcc084Schristos #endif 4393dcc084Schristos 4493dcc084Schristos #include <event2/event-config.h> 45*40f5f2eeSchristos #ifdef EVENT__HAVE_SYS_TYPES_H 4693dcc084Schristos #include <sys/types.h> 4793dcc084Schristos #endif 48*40f5f2eeSchristos #ifdef EVENT__HAVE_SYS_TIME_H 4993dcc084Schristos #include <sys/time.h> 5093dcc084Schristos #endif 5193dcc084Schristos 5293dcc084Schristos /* For int types. */ 5393dcc084Schristos #include <event2/util.h> 5493dcc084Schristos 5593dcc084Schristos /* For evkeyvalq */ 5693dcc084Schristos #include <event2/keyvalq_struct.h> 5793dcc084Schristos 5893dcc084Schristos #define EVLIST_TIMEOUT 0x01 5993dcc084Schristos #define EVLIST_INSERTED 0x02 6093dcc084Schristos #define EVLIST_SIGNAL 0x04 6193dcc084Schristos #define EVLIST_ACTIVE 0x08 6293dcc084Schristos #define EVLIST_INTERNAL 0x10 63*40f5f2eeSchristos #define EVLIST_ACTIVE_LATER 0x20 64*40f5f2eeSchristos #define EVLIST_FINALIZING 0x40 6593dcc084Schristos #define EVLIST_INIT 0x80 6693dcc084Schristos 67*40f5f2eeSchristos #define EVLIST_ALL 0xff 6893dcc084Schristos 6993dcc084Schristos /* Fix so that people don't have to run with <sys/queue.h> */ 7093dcc084Schristos #ifndef TAILQ_ENTRY 71*40f5f2eeSchristos #define EVENT_DEFINED_TQENTRY_ 7293dcc084Schristos #define TAILQ_ENTRY(type) \ 7393dcc084Schristos struct { \ 7493dcc084Schristos struct type *tqe_next; /* next element */ \ 7593dcc084Schristos struct type **tqe_prev; /* address of previous next element */ \ 7693dcc084Schristos } 7793dcc084Schristos #endif /* !TAILQ_ENTRY */ 7893dcc084Schristos 7993dcc084Schristos #ifndef TAILQ_HEAD 80*40f5f2eeSchristos #define EVENT_DEFINED_TQHEAD_ 8193dcc084Schristos #define TAILQ_HEAD(name, type) \ 8293dcc084Schristos struct name { \ 8393dcc084Schristos struct type *tqh_first; \ 8493dcc084Schristos struct type **tqh_last; \ 8593dcc084Schristos } 8693dcc084Schristos #endif 8793dcc084Schristos 88*40f5f2eeSchristos /* Fix so that people don't have to run with <sys/queue.h> */ 89*40f5f2eeSchristos #ifndef LIST_ENTRY 90*40f5f2eeSchristos #define EVENT_DEFINED_LISTENTRY_ 91*40f5f2eeSchristos #define LIST_ENTRY(type) \ 92*40f5f2eeSchristos struct { \ 93*40f5f2eeSchristos struct type *le_next; /* next element */ \ 94*40f5f2eeSchristos struct type **le_prev; /* address of previous next element */ \ 95*40f5f2eeSchristos } 96*40f5f2eeSchristos #endif /* !LIST_ENTRY */ 97*40f5f2eeSchristos 98*40f5f2eeSchristos #ifndef LIST_HEAD 99*40f5f2eeSchristos #define EVENT_DEFINED_LISTHEAD_ 100*40f5f2eeSchristos #define LIST_HEAD(name, type) \ 101*40f5f2eeSchristos struct name { \ 102*40f5f2eeSchristos struct type *lh_first; /* first element */ \ 103*40f5f2eeSchristos } 104*40f5f2eeSchristos #endif /* !LIST_HEAD */ 105*40f5f2eeSchristos 106*40f5f2eeSchristos struct event; 107*40f5f2eeSchristos 108*40f5f2eeSchristos struct event_callback { 109*40f5f2eeSchristos TAILQ_ENTRY(event_callback) evcb_active_next; 110*40f5f2eeSchristos short evcb_flags; 111*40f5f2eeSchristos ev_uint8_t evcb_pri; /* smaller numbers are higher priority */ 112*40f5f2eeSchristos ev_uint8_t evcb_closure; 113*40f5f2eeSchristos /* allows us to adopt for different types of events */ 114*40f5f2eeSchristos union { 115*40f5f2eeSchristos void (*evcb_callback)(evutil_socket_t, short, void *); 116*40f5f2eeSchristos void (*evcb_selfcb)(struct event_callback *, void *); 117*40f5f2eeSchristos void (*evcb_evfinalize)(struct event *, void *); 118*40f5f2eeSchristos void (*evcb_cbfinalize)(struct event_callback *, void *); 119*40f5f2eeSchristos } evcb_cb_union; 120*40f5f2eeSchristos void *evcb_arg; 121*40f5f2eeSchristos }; 122*40f5f2eeSchristos 12393dcc084Schristos struct event_base; 12493dcc084Schristos struct event { 125*40f5f2eeSchristos struct event_callback ev_evcallback; 126*40f5f2eeSchristos 12793dcc084Schristos /* for managing timeouts */ 12893dcc084Schristos union { 12993dcc084Schristos TAILQ_ENTRY(event) ev_next_with_common_timeout; 13093dcc084Schristos int min_heap_idx; 13193dcc084Schristos } ev_timeout_pos; 13293dcc084Schristos evutil_socket_t ev_fd; 13393dcc084Schristos 13493dcc084Schristos struct event_base *ev_base; 13593dcc084Schristos 13693dcc084Schristos union { 13793dcc084Schristos /* used for io events */ 13893dcc084Schristos struct { 139*40f5f2eeSchristos LIST_ENTRY (event) ev_io_next; 14093dcc084Schristos struct timeval ev_timeout; 14193dcc084Schristos } ev_io; 14293dcc084Schristos 14393dcc084Schristos /* used by signal events */ 14493dcc084Schristos struct { 145*40f5f2eeSchristos LIST_ENTRY (event) ev_signal_next; 14693dcc084Schristos short ev_ncalls; 14793dcc084Schristos /* Allows deletes in callback */ 14893dcc084Schristos short *ev_pncalls; 14993dcc084Schristos } ev_signal; 150*40f5f2eeSchristos } ev_; 15193dcc084Schristos 15293dcc084Schristos short ev_events; 15393dcc084Schristos short ev_res; /* result passed to event callback */ 15493dcc084Schristos struct timeval ev_timeout; 15593dcc084Schristos }; 15693dcc084Schristos 15793dcc084Schristos TAILQ_HEAD (event_list, event); 15893dcc084Schristos 159*40f5f2eeSchristos #ifdef EVENT_DEFINED_TQENTRY_ 16093dcc084Schristos #undef TAILQ_ENTRY 16193dcc084Schristos #endif 16293dcc084Schristos 163*40f5f2eeSchristos #ifdef EVENT_DEFINED_TQHEAD_ 16493dcc084Schristos #undef TAILQ_HEAD 16593dcc084Schristos #endif 16693dcc084Schristos 167*40f5f2eeSchristos LIST_HEAD (event_dlist, event); 168*40f5f2eeSchristos 169*40f5f2eeSchristos #ifdef EVENT_DEFINED_LISTENTRY_ 170*40f5f2eeSchristos #undef LIST_ENTRY 171*40f5f2eeSchristos #endif 172*40f5f2eeSchristos 173*40f5f2eeSchristos #ifdef EVENT_DEFINED_LISTHEAD_ 174*40f5f2eeSchristos #undef LIST_HEAD 175*40f5f2eeSchristos #endif 176*40f5f2eeSchristos 17793dcc084Schristos #ifdef __cplusplus 17893dcc084Schristos } 17993dcc084Schristos #endif 18093dcc084Schristos 181*40f5f2eeSchristos #endif /* EVENT2_EVENT_STRUCT_H_INCLUDED_ */ 182