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