Don't assume sa.sa_family is a short int.
[tinc] / src / event.h
index 6ec986d..0ff8e01 100644 (file)
@@ -1,7 +1,6 @@
 /*
-    event.h -- header for event.c
-    Copyright (C) 2002-2003 Guus Sliepen <guus@sliepen.eu.org>,
-                  2002-2003 Ivo Timmermans <ivo@o2w.nl>
+    event.h -- I/O, timeout and signal event handling
+    Copyright (C) 2012-2013 Guus Sliepen <guus@tinc-vpn.org>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
 
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-    $Id: event.h,v 1.1.4.8 2003/07/30 21:52:41 guus Exp $
+    You should have received a copy of the GNU General Public License along
+    with this program; if not, write to the Free Software Foundation, Inc.,
+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
 #ifndef __TINC_EVENT_H__
 #define __TINC_EVENT_H__
 
-#include "avl_tree.h"
+#include "splay_tree.h"
+
+#define IO_READ 1
+#define IO_WRITE 2
 
-extern avl_tree_t *event_tree;
+typedef void (*io_cb_t)(void *data, int flags);
+typedef void (*timeout_cb_t)(void *data);
+typedef void (*signal_cb_t)(void *data);
 
-typedef void (*event_handler_t)(void *);
+typedef struct io_t {
+       int fd;
+       int flags;
+#ifdef HAVE_MINGW
+       WSAEVENT event;
+#endif
+       io_cb_t cb;
+       void *data;
+       splay_node_t node;
+} io_t;
+
+typedef struct timeout_t {
+       struct timeval tv;
+       timeout_cb_t cb;
+       void *data;
+       splay_node_t node;
+} timeout_t;
 
-typedef struct {
-       time_t time;
-       int id;
-       event_handler_t handler;
+typedef struct signal_t {
+       int signum;
+       signal_cb_t cb;
        void *data;
-} event_t;
+       splay_node_t node;
+} signal_t;
+
+extern struct timeval now;
+
+extern void io_add(io_t *io, io_cb_t cb, void *data, int fd, int flags);
+#ifdef HAVE_MINGW
+extern void io_add_event(io_t *io, io_cb_t cb, void* data, WSAEVENT event);
+#endif
+extern void io_del(io_t *io);
+extern void io_set(io_t *io, int flags);
+
+extern void timeout_add(timeout_t *timeout, timeout_cb_t cb, void *data, struct timeval *tv);
+extern void timeout_del(timeout_t *timeout);
+extern void timeout_set(timeout_t *timeout, struct timeval *tv);
+
+extern void signal_add(signal_t *sig, signal_cb_t cb, void *data, int signum);
+extern void signal_del(signal_t *sig);
 
-extern void init_events(void);
-extern void exit_events(void);
-extern event_t *new_event(void) __attribute__ ((__malloc__));
-extern void free_event(event_t *);
-extern void event_add(event_t *);
-extern void event_del(event_t *);
-extern event_t *get_expired_event(void);
+extern bool event_loop(void);
+extern void event_exit(void);
 
-#endif                                                 /* __TINC_EVENT_H__ */
+#endif