apr_poll.inc 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. { Copyright 2000-2005 The Apache Software Foundation or its licensors, as
  2. * applicable.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. }
  16. {
  17. * @file apr_poll.h
  18. * @brief APR Poll interface
  19. }
  20. {#include "apr.h"
  21. #include "apr_pools.h"
  22. #include "apr_errno.h"
  23. #include "apr_inherit.h"
  24. #include "apr_file_io.h"
  25. #include "apr_network_io.h"
  26. #if APR_HAVE_NETINET_IN_H
  27. #include <netinet/in.h>
  28. #endif}
  29. {
  30. * @defgroup apr_poll Poll Routines
  31. * @ingroup APR
  32. }
  33. {
  34. * Poll options
  35. }
  36. const
  37. APR_POLLIN = $001; {< Can read without blocking }
  38. APR_POLLPRI = $002; {< Priority data available }
  39. APR_POLLOUT = $004; {< Can write without blocking }
  40. APR_POLLERR = $010; {< Pending error }
  41. APR_POLLHUP = $020; {< Hangup occurred }
  42. APR_POLLNVAL = $040; {< Descriptior invalid }
  43. {
  44. * Pollset Flags
  45. }
  46. APR_POLLSET_THREADSAFE = $001; {< Adding or Removing a Descriptor is thread safe }
  47. { Used in apr_pollfd_t to determine what the apr_descriptor is }
  48. type
  49. apr_datatype_e = (
  50. APR_NO_DESC, {< nothing here }
  51. APR_POLL_SOCKET, {< descriptor refers to a socket }
  52. APR_POLL_FILE, {< descriptor refers to a file }
  53. APR_POLL_LASTDESC {< descriptor is the last one in the list }
  54. );
  55. { Union of either an APR file or socket. }
  56. apr_descriptor = record
  57. case Integer of
  58. 1: (f: Papr_file_t); {< file }
  59. 2: (s: Papr_socket_t); {< socket }
  60. end;
  61. { @see apr_pollfd_t }
  62. Papr_pollfd_t = ^apr_pollfd_t;
  63. PPapr_pollfd_t = ^Papr_pollfd_t;
  64. { Poll descriptor set. }
  65. apr_pollfd_t = record
  66. p: Papr_pool_t; {< associated pool }
  67. desc_type: apr_datatype_e; {< descriptor type }
  68. reqevents: apr_int16_t; {< requested events }
  69. rtnevents: apr_int16_t; {< returned events }
  70. desc: apr_descriptor; {< @see apr_descriptor }
  71. client_data: Pointer; {< allows app to associate context }
  72. end;
  73. { General-purpose poll API for arbitrarily large numbers of
  74. * file descriptors
  75. }
  76. { Opaque structure used for pollset API }
  77. type
  78. apr_pollset_t = record end;
  79. Papr_pollset_t = ^apr_pollset_t;
  80. PPapr_pollset_t = ^Papr_pollset_t;
  81. {
  82. * Setup a pollset object
  83. * @param pollset The pointer in which to return the newly created object
  84. * @param size The maximum number of descriptors that this pollset can hold
  85. * @param p The pool from which to allocate the pollset
  86. * @param flags Optional flags to modify the operation of the pollset.
  87. *
  88. * @remark If flags equals APR_POLLSET_THREADSAFE, then a pollset is
  89. * created on which it is safe to make concurrent calls to
  90. * apr_pollset_add(), apr_pollset_remove() and apr_pollset_poll() from
  91. * separate threads. This feature is only supported on some
  92. * platforms; the apr_pollset_create() call will fail with
  93. * APR_ENOTIMPL on platforms where it is not supported.
  94. }
  95. function apr_pollset_create(pollset: PPapr_pollset_t; size: apr_uint32_tso_handle_t;
  96. p: Papr_pool_t; flags: apr_uint32_t): apr_status_t;
  97. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  98. external LibAPR name LibNamePrefix + 'apr_pollset_create' + LibSuff16;
  99. {
  100. * Destroy a pollset object
  101. * @param pollset The pollset to destroy
  102. }
  103. function apr_pollset_destroy(pollset: Papr_pollset_t): apr_status_t;
  104. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  105. external LibAPR name LibNamePrefix + 'apr_pollset_destroy' + LibSuff4;
  106. {
  107. * Add a socket or file descriptor to a pollset
  108. * @param pollset The pollset to which to add the descriptor
  109. * @param descriptor The descriptor to add
  110. * @remark If you set client_data in the descriptor, that value
  111. * will be returned in the client_data field whenever this
  112. * descriptor is signalled in apr_pollset_poll().
  113. * @remark If the pollset has been created with APR_POLLSET_THREADSAFE
  114. * and thread T1 is blocked in a call to apr_pollset_poll() for
  115. * this same pollset that is being modified via apr_pollset_add()
  116. * in thread T2, the currently executing apr_pollset_poll() call in
  117. * T1 will either: (1) automatically include the newly added descriptor
  118. * in the set of descriptors it is watching or (2) return immediately
  119. * with APR_EINTR. Option (1) is recommended, but option (2) is
  120. * allowed for implementations where option (1) is impossible
  121. * or impractical.
  122. }
  123. function apr_pollset_add(pollset: Papr_pollset_t;
  124. const descriptor: Papr_pollfd_t): apr_status_t;
  125. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  126. external LibAPR name LibNamePrefix + 'apr_pollset_add' + LibSuff8;
  127. {
  128. * Remove a descriptor from a pollset
  129. * @param pollset The pollset from which to remove the descriptor
  130. * @param descriptor The descriptor to remove
  131. * @remark If the pollset has been created with APR_POLLSET_THREADSAFE
  132. * and thread T1 is blocked in a call to apr_pollset_poll() for
  133. * this same pollset that is being modified via apr_pollset_remove()
  134. * in thread T2, the currently executing apr_pollset_poll() call in
  135. * T1 will either: (1) automatically exclude the newly added descriptor
  136. * in the set of descriptors it is watching or (2) return immediately
  137. * with APR_EINTR. Option (1) is recommended, but option (2) is
  138. * allowed for implementations where option (1) is impossible
  139. * or impractical.
  140. }
  141. function apr_pollset_remove(pollset: Papr_pollset_t;
  142. const descriptor: Papr_pollfd_t): apr_status_t;
  143. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  144. external LibAPR name LibNamePrefix + 'apr_pollset_remove' + LibSuff8;
  145. {
  146. * Block for activity on the descriptor(s) in a pollset
  147. * @param pollset The pollset to use
  148. * @param timeout Timeout in microseconds
  149. * @param num Number of signalled descriptors (output parameter)
  150. * @param descriptors Array of signalled descriptors (output parameter)
  151. }
  152. function apr_pollset_poll(pollset: Papr_pollset_t; timeout: apr_interval_time_t;
  153. num: Papr_int32_t; const descriptors: PPapr_pollfd_t): apr_status_t;
  154. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  155. external LibAPR name LibNamePrefix + 'apr_pollset_poll' + LibSuff20;
  156. {
  157. * Poll the descriptors in the poll structure
  158. * @param aprset The poll structure we will be using.
  159. * @param numsock The number of descriptors we are polling
  160. * @param nsds The number of descriptors signalled.
  161. * @param timeout The amount of time in microseconds to wait. This is
  162. * a maximum, not a minimum. If a descriptor is signalled, we
  163. * will wake up before this time. A negative number means
  164. * wait until a descriptor is signalled.
  165. * @remark The number of descriptors signalled is returned in the third argument.
  166. * This is a blocking call, and it will not return until either a
  167. * descriptor has been signalled, or the timeout has expired.
  168. * @remark The rtnevents field in the apr_pollfd_t array will only be filled-
  169. * in if the return value is APR_SUCCESS.
  170. }
  171. function apr_poll(aprset: Papr_pollfd_t; numsock: apr_int32_t;
  172. nsds: Papr_int32_t; timeout: apr_interval_time_t): apr_status_t;
  173. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  174. external LibAPR name LibNamePrefix + 'apr_poll' + LibSuff20;