big svn cleanup
[anytun.git] / src / openvpn / event.h
blob314ef4cac1a524b253d3470a233eeb8add11d802
1 /*
2 * OpenVPN -- An application to securely tunnel IP networks
3 * over a single TCP/UDP port, with support for SSL/TLS-based
4 * session authentication and key exchange,
5 * packet encryption, packet authentication, and
6 * packet compression.
8 * Copyright (C) 2002-2005 OpenVPN Solutions LLC <info@openvpn.net>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * as published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program (see the file COPYING included with this
21 * distribution); if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #ifndef EVENT_H
26 #define EVENT_H
28 #include "win32.h"
29 #include "sig.h"
30 #include "perf.h"
33 * rwflags passed to event_ctl and returned by
34 * struct event_set_return.
36 #define EVENT_READ (1<<0)
37 #define EVENT_WRITE (1<<1)
40 * Initialization flags passed to event_set_init
42 #define EVENT_METHOD_US_TIMEOUT (1<<0)
43 #define EVENT_METHOD_FAST (1<<1)
45 #ifdef WIN32
47 typedef const struct rw_handle *event_t;
49 #define UNDEFINED_EVENT (NULL)
51 #else
53 typedef int event_t;
55 #define UNDEFINED_EVENT (-1)
57 #endif
59 struct event_set;
60 struct event_set_return;
62 struct event_set_functions
64 void (*free)(struct event_set *es);
65 void (*reset)(struct event_set *es);
66 void (*del)(struct event_set *es, event_t event);
67 void (*ctl)(struct event_set *es, event_t event, unsigned int rwflags, void *arg);
70 * Return status for wait:
71 * -1 on signal or error
72 * 0 on timeout
73 * length of event_set_return if at least 1 event is returned
75 int (*wait)(struct event_set *es, const struct timeval *tv, struct event_set_return *out, int outlen);
78 struct event_set_return
80 unsigned int rwflags;
81 void *arg;
84 struct event_set
86 struct event_set_functions func;
90 * maxevents on input: desired max number of event_t descriptors
91 * simultaneously set with event_ctl
92 * maxevents on output: may be modified down, depending on limitations
93 * of underlying API
94 * flags: EVENT_METHOD_x flags
96 struct event_set *event_set_init (int *maxevents, unsigned int flags);
98 static inline void
99 event_free (struct event_set *es)
101 (*es->func.free)(es);
104 static inline void
105 event_reset (struct event_set *es)
107 (*es->func.reset)(es);
110 static inline void
111 event_del (struct event_set *es, event_t event)
113 (*es->func.del)(es, event);
116 static inline void
117 event_ctl (struct event_set *es, event_t event, unsigned int rwflags, void *arg)
119 (*es->func.ctl)(es, event, rwflags, arg);
122 static inline int
123 event_wait (struct event_set *es, const struct timeval *tv, struct event_set_return *out, int outlen)
125 int ret;
126 perf_push (PERF_IO_WAIT);
127 ret = (*es->func.wait)(es, tv, out, outlen);
128 perf_pop ();
129 return ret;
132 static inline void
133 event_set_return_init (struct event_set_return *esr)
135 esr->rwflags = 0;
136 esr->arg = NULL;
139 #ifdef WIN32
141 static inline void
142 wait_signal (struct event_set *es, void *arg)
144 if (HANDLE_DEFINED (win32_signal.in.read))
145 event_ctl (es, &win32_signal.in, EVENT_READ, arg);
148 #else
150 static inline void
151 wait_signal (struct event_set *es, void *arg)
155 #endif
157 #endif