Update to OpenVPN 2.1rc17
[tomato.git] / release / src / router / openvpn / event.h
bloba5698c5c14940bc20014753f1dec4f392a42d8fd
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-2009 OpenVPN Technologies, Inc. <sales@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_UNDEF 4
37 #define EVENT_READ (1<<0)
38 #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 if (es)
102 (*es->func.free)(es);
105 static inline void
106 event_reset (struct event_set *es)
108 (*es->func.reset)(es);
111 static inline void
112 event_del (struct event_set *es, event_t event)
114 (*es->func.del)(es, event);
117 static inline void
118 event_ctl (struct event_set *es, event_t event, unsigned int rwflags, void *arg)
120 (*es->func.ctl)(es, event, rwflags, arg);
123 static inline int
124 event_wait (struct event_set *es, const struct timeval *tv, struct event_set_return *out, int outlen)
126 int ret;
127 perf_push (PERF_IO_WAIT);
128 ret = (*es->func.wait)(es, tv, out, outlen);
129 perf_pop ();
130 return ret;
133 static inline void
134 event_set_return_init (struct event_set_return *esr)
136 esr->rwflags = 0;
137 esr->arg = NULL;
140 #ifdef WIN32
142 static inline void
143 wait_signal (struct event_set *es, void *arg)
145 if (HANDLE_DEFINED (win32_signal.in.read))
146 event_ctl (es, &win32_signal.in, EVENT_READ, arg);
149 #else
151 static inline void
152 wait_signal (struct event_set *es, void *arg)
156 #endif
158 #endif