tinc: update to 1.1pre11
[tomato.git] / release / src / router / tinc / src / event.h
blob0ff8e01c0ca7a0804351f88aaee7971b0983d526
1 /*
2 event.h -- I/O, timeout and signal event handling
3 Copyright (C) 2012-2013 Guus Sliepen <guus@tinc-vpn.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef __TINC_EVENT_H__
21 #define __TINC_EVENT_H__
23 #include "splay_tree.h"
25 #define IO_READ 1
26 #define IO_WRITE 2
28 typedef void (*io_cb_t)(void *data, int flags);
29 typedef void (*timeout_cb_t)(void *data);
30 typedef void (*signal_cb_t)(void *data);
32 typedef struct io_t {
33 int fd;
34 int flags;
35 #ifdef HAVE_MINGW
36 WSAEVENT event;
37 #endif
38 io_cb_t cb;
39 void *data;
40 splay_node_t node;
41 } io_t;
43 typedef struct timeout_t {
44 struct timeval tv;
45 timeout_cb_t cb;
46 void *data;
47 splay_node_t node;
48 } timeout_t;
50 typedef struct signal_t {
51 int signum;
52 signal_cb_t cb;
53 void *data;
54 splay_node_t node;
55 } signal_t;
57 extern struct timeval now;
59 extern void io_add(io_t *io, io_cb_t cb, void *data, int fd, int flags);
60 #ifdef HAVE_MINGW
61 extern void io_add_event(io_t *io, io_cb_t cb, void* data, WSAEVENT event);
62 #endif
63 extern void io_del(io_t *io);
64 extern void io_set(io_t *io, int flags);
66 extern void timeout_add(timeout_t *timeout, timeout_cb_t cb, void *data, struct timeval *tv);
67 extern void timeout_del(timeout_t *timeout);
68 extern void timeout_set(timeout_t *timeout, struct timeval *tv);
70 extern void signal_add(signal_t *sig, signal_cb_t cb, void *data, int signum);
71 extern void signal_del(signal_t *sig);
73 extern bool event_loop(void);
74 extern void event_exit(void);
76 #endif