2 event.h -- I/O and timeout event handling
3 Copyright (C) 2014 Guus Sliepen <guus@meshlink.io>
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 __MESHLINK_EVENT_H__
21 #define __MESHLINK_EVENT_H__
23 #include "splay_tree.h"
28 typedef struct event_loop_t event_loop_t;
30 typedef void (*io_cb_t)(event_loop_t *loop, void *data, int flags);
31 typedef void (*timeout_cb_t)(event_loop_t *loop, void *data);
38 struct splay_node_t node;
41 typedef struct timeout_t {
45 struct splay_node_t node;
52 volatile bool running;
56 splay_tree_t timeouts;
61 extern void io_add(event_loop_t *loop, io_t *io, io_cb_t cb, void *data, int fd, int flags);
62 extern void io_del(event_loop_t *loop, io_t *io);
63 extern void io_set(event_loop_t *loop, io_t *io, int flags);
65 extern void timeout_add(event_loop_t *loop, timeout_t *timeout, timeout_cb_t cb, void *data, struct timeval *tv);
66 extern void timeout_del(event_loop_t *loop, timeout_t *timeout);
67 extern void timeout_set(event_loop_t *loop, timeout_t *timeout, struct timeval *tv);
69 extern void event_loop_init(event_loop_t *loop);
70 extern void event_loop_exit(event_loop_t *loop);
71 extern bool event_loop_run(event_loop_t *loop);
72 extern void event_loop_flush_output(event_loop_t *loop);
73 extern void event_loop_stop(event_loop_t *loop);