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