Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:57:12

0001 /*
0002  * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
0003  * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
0004  *
0005  * Redistribution and use in source and binary forms, with or without
0006  * modification, are permitted provided that the following conditions
0007  * are met:
0008  * 1. Redistributions of source code must retain the above copyright
0009  *    notice, this list of conditions and the following disclaimer.
0010  * 2. Redistributions in binary form must reproduce the above copyright
0011  *    notice, this list of conditions and the following disclaimer in the
0012  *    documentation and/or other materials provided with the distribution.
0013  * 3. The name of the author may not be used to endorse or promote products
0014  *    derived from this software without specific prior written permission.
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
0017  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0018  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0019  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
0020  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
0021  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0022  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0023  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0024  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
0025  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0026  */
0027 #ifndef EVENT2_EVENT_STRUCT_H_INCLUDED_
0028 #define EVENT2_EVENT_STRUCT_H_INCLUDED_
0029 
0030 /** @file event2/event_struct.h
0031 
0032   Structures used by event.h.  Using these structures directly WILL harm
0033   forward compatibility: be careful.
0034 
0035   No field declared in this file should be used directly in user code.  Except
0036   for historical reasons, these fields would not be exposed at all.
0037  */
0038 
0039 #ifdef __cplusplus
0040 extern "C" {
0041 #endif
0042 
0043 #include <event2/event-config.h>
0044 #ifdef EVENT__HAVE_SYS_TYPES_H
0045 #include <sys/types.h>
0046 #endif
0047 #ifdef EVENT__HAVE_SYS_TIME_H
0048 #include <sys/time.h>
0049 #endif
0050 
0051 /* For int types. */
0052 #include <event2/util.h>
0053 
0054 /* For evkeyvalq */
0055 #include <event2/keyvalq_struct.h>
0056 
0057 #define EVLIST_TIMEOUT      0x01
0058 #define EVLIST_INSERTED     0x02
0059 #define EVLIST_SIGNAL       0x04
0060 #define EVLIST_ACTIVE       0x08
0061 #define EVLIST_INTERNAL     0x10
0062 #define EVLIST_ACTIVE_LATER 0x20
0063 #define EVLIST_FINALIZING   0x40
0064 #define EVLIST_INIT     0x80
0065 
0066 #define EVLIST_ALL          0xff
0067 
0068 /* Fix so that people don't have to run with <sys/queue.h> */
0069 #ifndef TAILQ_ENTRY
0070 #define EVENT_DEFINED_TQENTRY_
0071 #define TAILQ_ENTRY(type)                       \
0072 struct {                                \
0073     struct type *tqe_next;  /* next element */          \
0074     struct type **tqe_prev; /* address of previous next element */  \
0075 }
0076 #endif /* !TAILQ_ENTRY */
0077 
0078 #ifndef TAILQ_HEAD
0079 #define EVENT_DEFINED_TQHEAD_
0080 #define TAILQ_HEAD(name, type)          \
0081 struct name {                   \
0082     struct type *tqh_first;         \
0083     struct type **tqh_last;         \
0084 }
0085 #endif
0086 
0087 /* Fix so that people don't have to run with <sys/queue.h> */
0088 #ifndef LIST_ENTRY
0089 #define EVENT_DEFINED_LISTENTRY_
0090 #define LIST_ENTRY(type)                        \
0091 struct {                                \
0092     struct type *le_next;   /* next element */          \
0093     struct type **le_prev;  /* address of previous next element */  \
0094 }
0095 #endif /* !LIST_ENTRY */
0096 
0097 #ifndef LIST_HEAD
0098 #define EVENT_DEFINED_LISTHEAD_
0099 #define LIST_HEAD(name, type)                       \
0100 struct name {                               \
0101     struct type *lh_first;  /* first element */         \
0102     }
0103 #endif /* !LIST_HEAD */
0104 
0105 struct event;
0106 
0107 struct event_callback {
0108     TAILQ_ENTRY(event_callback) evcb_active_next;
0109     short evcb_flags;
0110     ev_uint8_t evcb_pri;    /* smaller numbers are higher priority */
0111     ev_uint8_t evcb_closure;
0112     /* allows us to adopt for different types of events */
0113         union {
0114         void (*evcb_callback)(evutil_socket_t, short, void *);
0115         void (*evcb_selfcb)(struct event_callback *, void *);
0116         void (*evcb_evfinalize)(struct event *, void *);
0117         void (*evcb_cbfinalize)(struct event_callback *, void *);
0118     } evcb_cb_union;
0119     void *evcb_arg;
0120 };
0121 
0122 struct event_base;
0123 struct event {
0124     struct event_callback ev_evcallback;
0125 
0126     /* for managing timeouts */
0127     union {
0128         TAILQ_ENTRY(event) ev_next_with_common_timeout;
0129         int min_heap_idx;
0130     } ev_timeout_pos;
0131     evutil_socket_t ev_fd;
0132 
0133     struct event_base *ev_base;
0134 
0135     union {
0136         /* used for io events */
0137         struct {
0138             LIST_ENTRY (event) ev_io_next;
0139             struct timeval ev_timeout;
0140         } ev_io;
0141 
0142         /* used by signal events */
0143         struct {
0144             LIST_ENTRY (event) ev_signal_next;
0145             short ev_ncalls;
0146             /* Allows deletes in callback */
0147             short *ev_pncalls;
0148         } ev_signal;
0149     } ev_;
0150 
0151     short ev_events;
0152     short ev_res;       /* result passed to event callback */
0153     struct timeval ev_timeout;
0154 };
0155 
0156 TAILQ_HEAD (event_list, event);
0157 
0158 #ifdef EVENT_DEFINED_TQENTRY_
0159 #undef TAILQ_ENTRY
0160 #endif
0161 
0162 #ifdef EVENT_DEFINED_TQHEAD_
0163 #undef TAILQ_HEAD
0164 #endif
0165 
0166 LIST_HEAD (event_dlist, event); 
0167 
0168 #ifdef EVENT_DEFINED_LISTENTRY_
0169 #undef LIST_ENTRY
0170 #endif
0171 
0172 #ifdef EVENT_DEFINED_LISTHEAD_
0173 #undef LIST_HEAD
0174 #endif
0175 
0176 #ifdef __cplusplus
0177 }
0178 #endif
0179 
0180 #endif /* EVENT2_EVENT_STRUCT_H_INCLUDED_ */