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
;
40 typedef void (*uloop_fd_handler
)(struct uloop_fd
*u
, unsigned int events
);
41 typedef void (*uloop_timeout_handler
)(struct uloop_timeout
*t
);
42 typedef void (*uloop_process_handler
)(struct uloop_process
*c
, int ret
);
43 typedef void (*uloop_interval_handler
)(struct uloop_interval
*t
);
45 #define ULOOP_READ (1 << 0)
46 #define ULOOP_WRITE (1 << 1)
47 #define ULOOP_EDGE_TRIGGER (1 << 2)
48 #define ULOOP_BLOCKING (1 << 3)
50 #define ULOOP_EVENT_MASK (ULOOP_READ | ULOOP_WRITE)
53 #define ULOOP_EVENT_BUFFERED (1 << 4)
55 #define ULOOP_EDGE_DEFER (1 << 5)
58 #define ULOOP_ERROR_CB (1 << 6)
72 struct list_head list
;
75 uloop_timeout_handler cb
;
81 struct list_head list
;
84 uloop_process_handler cb
;
90 uloop_interval_handler cb
;
102 extern bool uloop_cancelled
;
103 extern bool uloop_handle_sigchld
;
104 extern uloop_fd_handler uloop_fd_set_cb
;
106 int uloop_fd_add(struct uloop_fd
*sock
, unsigned int flags
);
107 int uloop_fd_delete(struct uloop_fd
*sock
);
109 int uloop_get_next_timeout(void);
110 int uloop_timeout_add(struct uloop_timeout
*timeout
);
111 int uloop_timeout_set(struct uloop_timeout
*timeout
, int msecs
);
112 int uloop_timeout_cancel(struct uloop_timeout
*timeout
);
113 int uloop_timeout_remaining(struct uloop_timeout
*timeout
) __attribute__((deprecated("use uloop_timeout_remaining64")));
114 int64_t uloop_timeout_remaining64(struct uloop_timeout
*timeout
);
116 int uloop_process_add(struct uloop_process
*p
);
117 int uloop_process_delete(struct uloop_process
*p
);
119 int uloop_interval_set(struct uloop_interval
*timer
, unsigned int msecs
);
120 int uloop_interval_cancel(struct uloop_interval
*timer
);
121 int64_t uloop_interval_remaining(struct uloop_interval
*timer
);
123 bool uloop_cancelling(void);
125 static inline void uloop_end(void)
127 uloop_cancelled
= true;
130 int uloop_init(void);
131 int uloop_run_timeout(int timeout
);
132 static inline int uloop_run(void)
134 return uloop_run_timeout(-1);
136 void uloop_done(void);