1 | /* Copyright (C) 2002-2022 Free Software Foundation, Inc. |
2 | This file is part of the GNU C Library. |
3 | |
4 | The GNU C Library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Lesser General Public |
6 | License as published by the Free Software Foundation; either |
7 | version 2.1 of the License, or (at your option) any later version. |
8 | |
9 | The GNU C Library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Lesser General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU Lesser General Public |
15 | License along with the GNU C Library; if not, see |
16 | <https://www.gnu.org/licenses/>. */ |
17 | |
18 | #ifndef _SYS_EPOLL_H |
19 | #define _SYS_EPOLL_H 1 |
20 | |
21 | #include <stdint.h> |
22 | #include <sys/types.h> |
23 | |
24 | #include <bits/types/sigset_t.h> |
25 | #include <bits/types/struct_timespec.h> |
26 | |
27 | /* Get the platform-dependent flags. */ |
28 | #include <bits/epoll.h> |
29 | |
30 | #ifndef __EPOLL_PACKED |
31 | # define __EPOLL_PACKED |
32 | #endif |
33 | |
34 | |
35 | enum EPOLL_EVENTS |
36 | { |
37 | EPOLLIN = 0x001, |
38 | #define EPOLLIN EPOLLIN |
39 | EPOLLPRI = 0x002, |
40 | #define EPOLLPRI EPOLLPRI |
41 | EPOLLOUT = 0x004, |
42 | #define EPOLLOUT EPOLLOUT |
43 | EPOLLRDNORM = 0x040, |
44 | #define EPOLLRDNORM EPOLLRDNORM |
45 | EPOLLRDBAND = 0x080, |
46 | #define EPOLLRDBAND EPOLLRDBAND |
47 | EPOLLWRNORM = 0x100, |
48 | #define EPOLLWRNORM EPOLLWRNORM |
49 | EPOLLWRBAND = 0x200, |
50 | #define EPOLLWRBAND EPOLLWRBAND |
51 | EPOLLMSG = 0x400, |
52 | #define EPOLLMSG EPOLLMSG |
53 | EPOLLERR = 0x008, |
54 | #define EPOLLERR EPOLLERR |
55 | EPOLLHUP = 0x010, |
56 | #define EPOLLHUP EPOLLHUP |
57 | EPOLLRDHUP = 0x2000, |
58 | #define EPOLLRDHUP EPOLLRDHUP |
59 | EPOLLEXCLUSIVE = 1u << 28, |
60 | #define EPOLLEXCLUSIVE EPOLLEXCLUSIVE |
61 | EPOLLWAKEUP = 1u << 29, |
62 | #define EPOLLWAKEUP EPOLLWAKEUP |
63 | EPOLLONESHOT = 1u << 30, |
64 | #define EPOLLONESHOT EPOLLONESHOT |
65 | EPOLLET = 1u << 31 |
66 | #define EPOLLET EPOLLET |
67 | }; |
68 | |
69 | |
70 | /* Valid opcodes ( "op" parameter ) to issue to epoll_ctl(). */ |
71 | #define EPOLL_CTL_ADD 1 /* Add a file descriptor to the interface. */ |
72 | #define EPOLL_CTL_DEL 2 /* Remove a file descriptor from the interface. */ |
73 | #define EPOLL_CTL_MOD 3 /* Change file descriptor epoll_event structure. */ |
74 | |
75 | |
76 | typedef union epoll_data |
77 | { |
78 | void *ptr; |
79 | int fd; |
80 | uint32_t u32; |
81 | uint64_t u64; |
82 | } epoll_data_t; |
83 | |
84 | struct epoll_event |
85 | { |
86 | uint32_t events; /* Epoll events */ |
87 | epoll_data_t data; /* User data variable */ |
88 | } __EPOLL_PACKED; |
89 | |
90 | |
91 | __BEGIN_DECLS |
92 | |
93 | /* Creates an epoll instance. Returns an fd for the new instance. |
94 | The "size" parameter is a hint specifying the number of file |
95 | descriptors to be associated with the new instance. The fd |
96 | returned by epoll_create() should be closed with close(). */ |
97 | extern int epoll_create (int __size) __THROW; |
98 | |
99 | /* Same as epoll_create but with an FLAGS parameter. The unused SIZE |
100 | parameter has been dropped. */ |
101 | extern int epoll_create1 (int __flags) __THROW; |
102 | |
103 | |
104 | /* Manipulate an epoll instance "epfd". Returns 0 in case of success, |
105 | -1 in case of error ( the "errno" variable will contain the |
106 | specific error code ) The "op" parameter is one of the EPOLL_CTL_* |
107 | constants defined above. The "fd" parameter is the target of the |
108 | operation. The "event" parameter describes which events the caller |
109 | is interested in and any associated user data. */ |
110 | extern int epoll_ctl (int __epfd, int __op, int __fd, |
111 | struct epoll_event *__event) __THROW; |
112 | |
113 | |
114 | /* Wait for events on an epoll instance "epfd". Returns the number of |
115 | triggered events returned in "events" buffer. Or -1 in case of |
116 | error with the "errno" variable set to the specific error code. The |
117 | "events" parameter is a buffer that will contain triggered |
118 | events. The "maxevents" is the maximum number of events to be |
119 | returned ( usually size of "events" ). The "timeout" parameter |
120 | specifies the maximum wait time in milliseconds (-1 == infinite). |
121 | |
122 | This function is a cancellation point and therefore not marked with |
123 | __THROW. */ |
124 | extern int epoll_wait (int __epfd, struct epoll_event *__events, |
125 | int __maxevents, int __timeout); |
126 | |
127 | |
128 | /* Same as epoll_wait, but the thread's signal mask is temporarily |
129 | and atomically replaced with the one provided as parameter. |
130 | |
131 | This function is a cancellation point and therefore not marked with |
132 | __THROW. */ |
133 | extern int epoll_pwait (int __epfd, struct epoll_event *__events, |
134 | int __maxevents, int __timeout, |
135 | const __sigset_t *__ss); |
136 | |
137 | /* Same as epoll_pwait, but the timeout as a timespec. |
138 | |
139 | This function is a cancellation point and therefore not marked with |
140 | __THROW. */ |
141 | #ifndef __USE_TIME_BITS64 |
142 | extern int epoll_pwait2 (int __epfd, struct epoll_event *__events, |
143 | int __maxevents, const struct timespec *__timeout, |
144 | const __sigset_t *__ss); |
145 | #else |
146 | # ifdef __REDIRECT |
147 | extern int __REDIRECT (epoll_pwait2, (int __epfd, struct epoll_event *__ev, |
148 | int __maxevs, |
149 | const struct timespec *__timeout, |
150 | const __sigset_t *__ss), |
151 | __epoll_pwait2_time64); |
152 | # else |
153 | # define epoll_pwait2 __epoll_pwait2_time64 |
154 | # endif |
155 | #endif |
156 | |
157 | __END_DECLS |
158 | |
159 | #endif /* sys/epoll.h */ |
160 | |