epoll.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* Copyright (C) 2002-2006, 2007, 2008, 2009 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, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. #ifndef _SYS_EPOLL_H
  16. #define _SYS_EPOLL_H 1
  17. #include <stdint.h>
  18. #include <sys/types.h>
  19. /* Get __sigset_t. */
  20. #include <bits/sigset.h>
  21. #ifndef __sigset_t_defined
  22. # define __sigset_t_defined
  23. typedef __sigset_t sigset_t;
  24. #endif
  25. /* Flags to be passed to epoll_create1. */
  26. enum
  27. {
  28. #if defined __alpha__
  29. EPOLL_CLOEXEC = 010000000,
  30. # define EPOLL_CLOEXEC EPOLL_CLOEXEC
  31. EPOLL_NONBLOCK = 04
  32. # define EPOLL_NONBLOCK EPOLL_NONBLOCK
  33. #else
  34. # if defined __sparc__
  35. EPOLL_CLOEXEC = 020000000,
  36. # else
  37. EPOLL_CLOEXEC = 02000000,
  38. # endif
  39. # define EPOLL_CLOEXEC EPOLL_CLOEXEC
  40. # if defined __mips__
  41. EPOLL_NONBLOCK = 0200
  42. # elif defined __sparc__
  43. EPOLL_NONBLOCK = 040000
  44. # else
  45. EPOLL_NONBLOCK = 04000
  46. # endif
  47. #define EPOLL_NONBLOCK EPOLL_NONBLOCK
  48. #endif
  49. };
  50. enum EPOLL_EVENTS
  51. {
  52. EPOLLIN = 0x001,
  53. #define EPOLLIN EPOLLIN
  54. EPOLLPRI = 0x002,
  55. #define EPOLLPRI EPOLLPRI
  56. EPOLLOUT = 0x004,
  57. #define EPOLLOUT EPOLLOUT
  58. EPOLLRDNORM = 0x040,
  59. #define EPOLLRDNORM EPOLLRDNORM
  60. EPOLLRDBAND = 0x080,
  61. #define EPOLLRDBAND EPOLLRDBAND
  62. EPOLLWRNORM = 0x100,
  63. #define EPOLLWRNORM EPOLLWRNORM
  64. EPOLLWRBAND = 0x200,
  65. #define EPOLLWRBAND EPOLLWRBAND
  66. EPOLLMSG = 0x400,
  67. #define EPOLLMSG EPOLLMSG
  68. EPOLLERR = 0x008,
  69. #define EPOLLERR EPOLLERR
  70. EPOLLHUP = 0x010,
  71. #define EPOLLHUP EPOLLHUP
  72. EPOLLRDHUP = 0x2000,
  73. #define EPOLLRDHUP EPOLLRDHUP
  74. EPOLLONESHOT = (1 << 30),
  75. #define EPOLLONESHOT EPOLLONESHOT
  76. EPOLLET = (1 << 31)
  77. #define EPOLLET EPOLLET
  78. };
  79. /* Valid opcodes ( "op" parameter ) to issue to epoll_ctl(). */
  80. #define EPOLL_CTL_ADD 1 /* Add a file descriptor to the interface. */
  81. #define EPOLL_CTL_DEL 2 /* Remove a file descriptor from the interface. */
  82. #define EPOLL_CTL_MOD 3 /* Change file descriptor epoll_event structure. */
  83. typedef union epoll_data
  84. {
  85. void *ptr;
  86. int fd;
  87. uint32_t u32;
  88. uint64_t u64;
  89. } epoll_data_t;
  90. struct epoll_event
  91. {
  92. uint32_t events; /* Epoll events */
  93. epoll_data_t data; /* User data variable */
  94. }
  95. #if defined __x86_64__
  96. __attribute__((packed))
  97. #endif
  98. ;
  99. __BEGIN_DECLS
  100. /* Creates an epoll instance. Returns an fd for the new instance.
  101. The "size" parameter is a hint specifying the number of file
  102. descriptors to be associated with the new instance. The fd
  103. returned by epoll_create() should be closed with close(). */
  104. extern int epoll_create (int __size) __THROW;
  105. /* Same as epoll_create but with a FLAGS parameter. The unused SIZE
  106. parameter has been dropped. */
  107. extern int epoll_create1 (int __flags) __THROW;
  108. /* Manipulate an epoll instance "epfd". Returns 0 in case of success,
  109. -1 in case of error ( the "errno" variable will contain the
  110. specific error code ) The "op" parameter is one of the EPOLL_CTL_*
  111. constants defined above. The "fd" parameter is the target of the
  112. operation. The "event" parameter describes which events the caller
  113. is interested in and any associated user data. */
  114. extern int epoll_ctl (int __epfd, int __op, int __fd,
  115. struct epoll_event *__event) __THROW;
  116. /* Wait for events on an epoll instance "epfd". Returns the number of
  117. triggered events returned in "events" buffer. Or -1 in case of
  118. error with the "errno" variable set to the specific error code. The
  119. "events" parameter is a buffer that will contain triggered
  120. events. The "maxevents" is the maximum number of events to be
  121. returned ( usually size of "events" ). The "timeout" parameter
  122. specifies the maximum wait time in milliseconds (-1 == infinite).
  123. This function is a cancellation point and therefore not marked with
  124. __THROW. */
  125. extern int epoll_wait (int __epfd, struct epoll_event *__events,
  126. int __maxevents, int __timeout);
  127. /* Same as epoll_wait, but the thread's signal mask is temporarily
  128. and atomically replaced with the one provided as parameter.
  129. This function is a cancellation point and therefore not marked with
  130. __THROW. */
  131. extern int epoll_pwait (int __epfd, struct epoll_event *__events,
  132. int __maxevents, int __timeout,
  133. __const __sigset_t *__ss);
  134. __END_DECLS
  135. #endif /* sys/epoll.h */