1
0

epoll.h 6.1 KB

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