epoll.h 4.4 KB

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