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__)
38 struct uloop_interval
;
41 typedef void (*uloop_fd_handler
)(struct uloop_fd
*u
, unsigned int events
);
42 typedef void (*uloop_timeout_handler
)(struct uloop_timeout
*t
);
43 typedef void (*uloop_process_handler
)(struct uloop_process
*c
, int ret
);
44 typedef void (*uloop_interval_handler
)(struct uloop_interval
*t
);
45 typedef void (*uloop_signal_handler
)(struct uloop_signal
*s
);
47 #define ULOOP_READ (1 << 0)
48 #define ULOOP_WRITE (1 << 1)
49 #define ULOOP_EDGE_TRIGGER (1 << 2)
50 #define ULOOP_BLOCKING (1 << 3)
52 #define ULOOP_EVENT_MASK (ULOOP_READ | ULOOP_WRITE)
55 #define ULOOP_EVENT_BUFFERED (1 << 4)
57 #define ULOOP_EDGE_DEFER (1 << 5)
60 #define ULOOP_ERROR_CB (1 << 6)
74 struct list_head list
;
77 uloop_timeout_handler cb
;
83 struct list_head list
;
86 uloop_process_handler cb
;
92 uloop_interval_handler cb
;
106 struct list_head list
;
107 struct sigaction orig
;
110 uloop_signal_handler cb
;
114 extern bool uloop_cancelled
;
115 extern bool uloop_handle_sigchld
;
116 extern uloop_fd_handler uloop_fd_set_cb
;
118 int uloop_fd_add(struct uloop_fd
*sock
, unsigned int flags
);
119 int uloop_fd_delete(struct uloop_fd
*sock
);
121 int uloop_get_next_timeout(void);
122 int uloop_timeout_add(struct uloop_timeout
*timeout
);
123 int uloop_timeout_set(struct uloop_timeout
*timeout
, int msecs
);
124 int uloop_timeout_cancel(struct uloop_timeout
*timeout
);
125 int uloop_timeout_remaining(struct uloop_timeout
*timeout
) __attribute__((deprecated("use uloop_timeout_remaining64")));
126 int64_t uloop_timeout_remaining64(struct uloop_timeout
*timeout
);
128 int uloop_process_add(struct uloop_process
*p
);
129 int uloop_process_delete(struct uloop_process
*p
);
131 int uloop_interval_set(struct uloop_interval
*timer
, unsigned int msecs
);
132 int uloop_interval_cancel(struct uloop_interval
*timer
);
133 int64_t uloop_interval_remaining(struct uloop_interval
*timer
);
135 int uloop_signal_add(struct uloop_signal
*s
);
136 int uloop_signal_delete(struct uloop_signal
*s
);
138 bool uloop_cancelling(void);
140 static inline void uloop_end(void)
142 uloop_cancelled
= true;
145 int uloop_init(void);
146 int uloop_run_timeout(int timeout
);
147 static inline int uloop_run(void)
149 return uloop_run_timeout(-1);
151 void uloop_done(void);