poll.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*++
  2. Copyright (c) 2013 Minoca Corp.
  3. This file is licensed under the terms of the GNU Lesser General Public
  4. License version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details.
  6. Module Name:
  7. poll.h
  8. Abstract:
  9. This header contains definitions for the poll function.
  10. Author:
  11. Evan Green 3-May-2013
  12. --*/
  13. #ifndef _POLL_H
  14. #define _POLL_H
  15. //
  16. // ------------------------------------------------------------------- Includes
  17. //
  18. #include <libcbase.h>
  19. #include <time.h>
  20. //
  21. // ---------------------------------------------------------------- Definitions
  22. //
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. //
  27. // This value specifies that data other than high priority data may be read
  28. // without blocking.
  29. //
  30. #define POLLIN 0x0001
  31. #define POLLRDNORM POLLIN
  32. //
  33. // This value specifies that priority data may be read without blocking.
  34. //
  35. #define POLLRDBAND 0x0002
  36. #define POLLPRI POLLRDBAND
  37. //
  38. // This value specifies that normal data may be written without blocking.
  39. //
  40. #define POLLOUT 0x0004
  41. #define POLLWRNORM POLLOUT
  42. //
  43. // This value specifies that priority data may be written.
  44. //
  45. #define POLLWRBAND 0x0008
  46. //
  47. // This value specifies that the descriptor suffered an error. It is only set
  48. // in the return events, and is ignored if set in events.
  49. //
  50. #define POLLERR 0x0010
  51. //
  52. // This value specifies that the device backing the I/O descriptor has
  53. // disconnected. It is only set in the return events, and is ignored if set
  54. // in events.
  55. //
  56. #define POLLHUP 0x0020
  57. //
  58. // This value indicates that the specified file descriptor is invalid. It is
  59. // only set in return events, and is ignored if set in events.
  60. //
  61. #define POLLNVAL 0x0040
  62. //
  63. // ------------------------------------------------------ Data Type Definitions
  64. //
  65. /*++
  66. Structure Description:
  67. This structure defines a polled file descriptor.
  68. Members:
  69. fd - Stores the descriptor being polled.
  70. events - Stores the mask of events to poll on.
  71. revents - Stores the mask of events that apply to this descriptor.
  72. --*/
  73. struct pollfd {
  74. int fd;
  75. short events;
  76. short revents;
  77. };
  78. //
  79. // Define the size of the "number of file descriptors" type.
  80. //
  81. typedef unsigned long nfds_t;
  82. //
  83. // -------------------------------------------------------------------- Globals
  84. //
  85. //
  86. // -------------------------------------------------------- Function Prototypes
  87. //
  88. LIBC_API
  89. int
  90. poll (
  91. struct pollfd PollDescriptors[],
  92. nfds_t DescriptorCount,
  93. int Timeout
  94. );
  95. /*++
  96. Routine Description:
  97. This routine blocks waiting for specified activity on a range of file
  98. descriptors.
  99. Arguments:
  100. PollDescriptors - Supplies an array of poll descriptor structures,
  101. indicating which descriptors should be waited on and which events
  102. should qualify in each descriptor.
  103. DescriptorCount - Supplies the number of descriptors in the array.
  104. Timeout - Supplies the amount of time in milliseconds to block before
  105. giving up and returning anyway. Supply 0 to not block at all, and
  106. supply -1 to wait for an indefinite amount of time.
  107. Return Value:
  108. Returns a positive number to indicate success and the number of file
  109. descriptors that had events occur.
  110. Returns 0 to indicate a timeout.
  111. Returns -1 to indicate an error, and errno will be set to contain more
  112. information.
  113. --*/
  114. LIBC_API
  115. int
  116. ppoll (
  117. struct pollfd PollDescriptors[],
  118. nfds_t DescriptorCount,
  119. const struct timespec *Timeout,
  120. const sigset_t *SignalMask
  121. );
  122. /*++
  123. Routine Description:
  124. This routine blocks waiting for specified activity on a range of file
  125. descriptors.
  126. Arguments:
  127. PollDescriptors - Supplies an array of poll descriptor structures,
  128. indicating which descriptors should be waited on and which events
  129. should qualify in each descriptor.
  130. DescriptorCount - Supplies the number of descriptors in the array.
  131. Timeout - Supplies the amount of time to block before giving up and
  132. returning anyway. Supply 0 to not block at all, and supply -1 to wait
  133. for an indefinite amount of time. The timeout will be at least as long
  134. as supplied, but may also be rounded up.
  135. SignalMask - Supplies an optional pointer to a signal mask to set
  136. atomically for the duration of the wait.
  137. Return Value:
  138. Returns a positive number to indicate success and the number of file
  139. descriptors that had events occur.
  140. Returns 0 to indicate a timeout.
  141. Returns -1 to indicate an error, and errno will be set to contain more
  142. information.
  143. --*/
  144. #ifdef __cplusplus
  145. }
  146. #endif
  147. #endif