epoll.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* Copyright (C) 2002-2021 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/types.h>
  18. #include <bits/types/sigset_t.h>
  19. /* Get the platform-dependent flags. */
  20. #include <bits/epoll.h>
  21. #ifndef __EPOLL_PACKED
  22. # define __EPOLL_PACKED
  23. #endif
  24. enum EPOLL_EVENTS
  25. {
  26. EPOLLIN = 0x001,
  27. #define EPOLLIN EPOLLIN
  28. EPOLLPRI = 0x002,
  29. #define EPOLLPRI EPOLLPRI
  30. EPOLLOUT = 0x004,
  31. #define EPOLLOUT EPOLLOUT
  32. EPOLLRDNORM = 0x040,
  33. #define EPOLLRDNORM EPOLLRDNORM
  34. EPOLLRDBAND = 0x080,
  35. #define EPOLLRDBAND EPOLLRDBAND
  36. EPOLLWRNORM = 0x100,
  37. #define EPOLLWRNORM EPOLLWRNORM
  38. EPOLLWRBAND = 0x200,
  39. #define EPOLLWRBAND EPOLLWRBAND
  40. EPOLLMSG = 0x400,
  41. #define EPOLLMSG EPOLLMSG
  42. EPOLLERR = 0x008,
  43. #define EPOLLERR EPOLLERR
  44. EPOLLHUP = 0x010,
  45. #define EPOLLHUP EPOLLHUP
  46. EPOLLRDHUP = 0x2000,
  47. #define EPOLLRDHUP EPOLLRDHUP
  48. EPOLLEXCLUSIVE = 1u << 28,
  49. #define EPOLLEXCLUSIVE EPOLLEXCLUSIVE
  50. EPOLLWAKEUP = 1u << 29,
  51. #define EPOLLWAKEUP EPOLLWAKEUP
  52. EPOLLONESHOT = 1u << 30,
  53. #define EPOLLONESHOT EPOLLONESHOT
  54. EPOLLET = 1u << 31
  55. #define EPOLLET EPOLLET
  56. };
  57. /* Valid opcodes ( "op" parameter ) to issue to epoll_ctl(). */
  58. #define EPOLL_CTL_ADD 1 /* Add a file descriptor to the interface. */
  59. #define EPOLL_CTL_DEL 2 /* Remove a file descriptor from the interface. */
  60. #define EPOLL_CTL_MOD 3 /* Change file descriptor epoll_event structure. */
  61. typedef union epoll_data
  62. {
  63. void *ptr;
  64. int fd;
  65. uint32_t u32;
  66. uint64_t u64;
  67. } epoll_data_t;
  68. struct epoll_event
  69. {
  70. uint32_t events; /* Epoll events */
  71. epoll_data_t data; /* User data variable */
  72. } __EPOLL_PACKED;
  73. __BEGIN_DECLS
  74. /* Creates an epoll instance. Returns an fd for the new instance.
  75. The "size" parameter is a hint specifying the number of file
  76. descriptors to be associated with the new instance. The fd
  77. returned by epoll_create() should be closed with close(). */
  78. extern int epoll_create (int __size) __THROW;
  79. /* Same as epoll_create but with an FLAGS parameter. The unused SIZE
  80. parameter has been dropped. */
  81. extern int epoll_create1 (int __flags) __THROW;
  82. /* Manipulate an epoll instance "epfd". Returns 0 in case of success,
  83. -1 in case of error ( the "errno" variable will contain the
  84. specific error code ) The "op" parameter is one of the EPOLL_CTL_*
  85. constants defined above. The "fd" parameter is the target of the
  86. operation. The "event" parameter describes which events the caller
  87. is interested in and any associated user data. */
  88. extern int epoll_ctl (int __epfd, int __op, int __fd,
  89. struct epoll_event *__event) __THROW;
  90. /* Wait for events on an epoll instance "epfd". Returns the number of
  91. triggered events returned in "events" buffer. Or -1 in case of
  92. error with the "errno" variable set to the specific error code. The
  93. "events" parameter is a buffer that will contain triggered
  94. events. The "maxevents" is the maximum number of events to be
  95. returned ( usually size of "events" ). The "timeout" parameter
  96. specifies the maximum wait time in milliseconds (-1 == infinite).
  97. This function is a cancellation point and therefore not marked with
  98. __THROW. */
  99. extern int epoll_wait (int __epfd, struct epoll_event *__events,
  100. int __maxevents, int __timeout);
  101. /* Same as epoll_wait, but the thread's signal mask is temporarily
  102. and atomically replaced with the one provided as parameter.
  103. This function is a cancellation point and therefore not marked with
  104. __THROW. */
  105. extern int epoll_pwait (int __epfd, struct epoll_event *__events,
  106. int __maxevents, int __timeout,
  107. const __sigset_t *__ss);
  108. __END_DECLS
  109. #endif /* sys/epoll.h */