2 * uloop - event loop implementation
4 * Copyright (C) 2010-2013 Felix Fietkau <nbd@openwrt.org>
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 #include <sys/types.h>
27 #if defined(__APPLE__) || defined(__FreeBSD__)
39 typedef void (*uloop_fd_handler)(struct uloop_fd *u, unsigned int events);
40 typedef void (*uloop_timeout_handler)(struct uloop_timeout *t);
41 typedef void (*uloop_process_handler)(struct uloop_process *c, int ret);
43 #define ULOOP_READ (1 << 0)
44 #define ULOOP_WRITE (1 << 1)
45 #define ULOOP_EDGE_TRIGGER (1 << 2)
46 #define ULOOP_BLOCKING (1 << 3)
48 #define ULOOP_EDGE_DEFER (1 << 4)
65 struct list_head list;
68 uloop_timeout_handler cb;
74 struct list_head list;
77 uloop_process_handler cb;
81 extern bool uloop_cancelled;
82 extern bool uloop_handle_sigchld;
84 int uloop_fd_add(struct uloop_fd *sock, unsigned int flags);
85 int uloop_fd_delete(struct uloop_fd *sock);
87 int uloop_timeout_add(struct uloop_timeout *timeout);
88 int uloop_timeout_set(struct uloop_timeout *timeout, int msecs);
89 int uloop_timeout_cancel(struct uloop_timeout *timeout);
90 int uloop_timeout_remaining(struct uloop_timeout *timeout);
92 int uloop_process_add(struct uloop_process *p);
93 int uloop_process_delete(struct uloop_process *p);
95 static inline void uloop_end(void)
97 uloop_cancelled = true;
100 int uloop_init(void);
101 void uloop_run(void);
102 void uloop_done(void);