1 /* 2 * uloop - event loop implementation 3 * 4 * Copyright (C) 2010-2013 Felix Fietkau <nbd@openwrt.org> 5 * 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. 9 * 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. 17 */ 18 #ifndef _ULOOP_H__ 19 #define _ULOOP_H__ 20 21 #include <sys/time.h> 22 #include <sys/types.h> 23 #include <stdbool.h> 24 #include <stdint.h> 25 #include <signal.h> 26 27 #if defined(__APPLE__) || defined(__FreeBSD__) 28 #define USE_KQUEUE 29 #else 30 #define USE_EPOLL 31 #endif 32 33 #include "list.h" 34 35 struct uloop_fd; 36 struct uloop_timeout; 37 struct uloop_process; 38 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); 42 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) 47 48 #define ULOOP_EVENT_MASK (ULOOP_READ | ULOOP_WRITE) 49 50 /* internal flags */ 51 #define ULOOP_EVENT_BUFFERED (1 << 4) 52 #ifdef USE_KQUEUE 53 #define ULOOP_EDGE_DEFER (1 << 5) 54 #endif 55 56 #define ULOOP_ERROR_CB (1 << 6) 57 58 struct uloop_fd 59 { 60 uloop_fd_handler cb; 61 int fd; 62 bool eof; 63 bool error; 64 bool registered; 65 uint8_t flags; 66 }; 67 68 struct uloop_timeout 69 { 70 struct list_head list; 71 bool pending; 72 73 uloop_timeout_handler cb; 74 struct timeval time; 75 }; 76 77 struct uloop_process 78 { 79 struct list_head list; 80 bool pending; 81 82 uloop_process_handler cb; 83 pid_t pid; 84 }; 85 86 extern bool uloop_cancelled; 87 extern bool uloop_handle_sigchld; 88 89 int uloop_fd_add(struct uloop_fd *sock, unsigned int flags); 90 int uloop_fd_delete(struct uloop_fd *sock); 91 92 int uloop_timeout_add(struct uloop_timeout *timeout); 93 int uloop_timeout_set(struct uloop_timeout *timeout, int msecs); 94 int uloop_timeout_cancel(struct uloop_timeout *timeout); 95 int uloop_timeout_remaining(struct uloop_timeout *timeout) __attribute__((deprecated("use uloop_timeout_remaining64"))); 96 int64_t uloop_timeout_remaining64(struct uloop_timeout *timeout); 97 98 int uloop_process_add(struct uloop_process *p); 99 int uloop_process_delete(struct uloop_process *p); 100 101 bool uloop_cancelling(void); 102 103 static inline void uloop_end(void) 104 { 105 uloop_cancelled = true; 106 } 107 108 int uloop_init(void); 109 int uloop_run_timeout(int timeout); 110 static inline int uloop_run(void) 111 { 112 return uloop_run_timeout(-1); 113 } 114 void uloop_done(void); 115 116 #endif 117
This page was automatically generated by LXR 0.3.1. • OpenWrt