epoll.h 5.5 KB

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