1 /**
2 * @file epoll.h
3 * epoll.h API header file.
4 *
5 * @version V1.0
6 * @date 2020-04-26
7 * @copyright Copyright (C) 2015-2020 Alibaba Group Holding Limited
8 */
9
10 #ifndef ___EPOLL_H__
11 #define ___EPOLL_H__
12
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16
17 #include <stdint.h>
18
19 #define EPOLL_CTL_ADD 1
20 #define EPOLL_CTL_DEL 2
21 #define EPOLL_CTL_MOD 3
22
23 #ifndef O_CLOEXEC
24 #define O_CLOEXEC 02000000
25 #endif
26
27 #define EPOLL_CLOEXEC O_CLOEXEC
28
29 enum EPOLL_EVENTS
30 {
31 EPOLLIN = 0x001,
32 EPOLLPRI = 0x002,
33 EPOLLOUT = 0x004,
34 EPOLLRDNORM = 0x040,
35 EPOLLRDBAND = 0x080,
36 EPOLLWRNORM = 0x100,
37 EPOLLWRBAND = 0x200,
38 EPOLLMSG = 0x400,
39 EPOLLERR = 0x008,
40 EPOLLHUP = 0x010,
41 EPOLLRDHUP = 0x2000,
42 EPOLLEXCLUSIVE = 1u << 28,
43 EPOLLWAKEUP = 1u << 29,
44 EPOLLONESHOT = 1u << 30,
45 EPOLLET = 1u << 31
46 };
47
48 typedef union epoll_data {
49 void *ptr;
50 int fd;
51 uint32_t u32;
52 uint64_t u64;
53 } epoll_data_t;
54
55 typedef struct epoll_event {
56 uint32_t events;
57 epoll_data_t data;
58 } epoll_event_t;
59
60 int aos_epoll_create(int size);
61 int aos_epoll_create1(int flag);
62 int aos_epoll_ctl(int epid, int op, int sockid, struct epoll_event *event);
63 int aos_epoll_wait(int epid, struct epoll_event *events, int maxevents, int timeout);
64
65 #if (!CONFIG_WITH_MUSL)
epoll_create(int size)66 static inline int epoll_create(int size)
67 {
68 return aos_epoll_create(size);
69 }
70
epoll_create1(int flag)71 static inline int epoll_create1(int flag)
72 {
73 return aos_epoll_create1(flag);
74 }
75
epoll_ctl(int epid,int op,int sockid,struct epoll_event * event)76 static inline int epoll_ctl(int epid, int op, int sockid, struct epoll_event *event)
77 {
78 return aos_epoll_ctl(epid, op, sockid, event);
79 }
80
epoll_wait(int epid,struct epoll_event * events,int maxevents,int timeout)81 static inline int epoll_wait(int epid, struct epoll_event *events, int maxevents, int timeout)
82 {
83 return aos_epoll_wait(epid, events, maxevents, timeout);
84 }
85 #endif
86
87 #ifdef __cplusplus
88 }
89 #endif
90
91 #endif
92