apr_poll.inc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. * @defgroup apr_poll_opt 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. { Used in apr_pollfd_t to determine what the apr_descriptor is }
  44. type
  45. apr_datatype_e = (
  46. APR_NO_DESC, {< nothing here }
  47. APR_POLL_SOCKET, {< descriptor refers to a socket }
  48. APR_POLL_FILE, {< descriptor refers to a file }
  49. APR_POLL_LASTDESC {< descriptor is the last one in the list }
  50. );
  51. { Union of either an APR file or socket. }
  52. apr_descriptor = record
  53. case Integer of
  54. 1: (f: Papr_file_t); {< file }
  55. 2: (s: Papr_socket_t); {< socket }
  56. end;
  57. { @see apr_pollfd_t }
  58. Papr_pollfd_t = ^apr_pollfd_t;
  59. PPapr_pollfd_t = ^Papr_pollfd_t;
  60. { Poll descriptor set. }
  61. apr_pollfd_t = record
  62. p: Papr_pool_t; {< associated pool }
  63. desc_type: apr_datatype_e; {< descriptor type }
  64. reqevents: apr_int16_t; {< requested events }
  65. rtnevents: apr_int16_t; {< returned events }
  66. desc: apr_descriptor; {< @see apr_descriptor }
  67. client_data: Pointer; {< allows app to associate context }
  68. end;
  69. {
  70. * Setup the memory required for poll to operate properly
  71. * @param new_poll The poll structure to be used.
  72. * @param num The number of socket descriptors to be polled.
  73. * @param cont The pool to operate on.
  74. * @deprecated This function is deprecated, APR applications should control the pollset memory themselves.
  75. }
  76. function apr_poll_setup(new_poll: PPapr_pollfd_t; num: apr_int32_t;
  77. cont: Papr_pool_t): apr_status_t;
  78. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  79. external LibAPR name LibNamePrefix + 'apr_poll_setup' + LibSuff12;
  80. {
  81. * Poll the sockets in the poll structure
  82. * @param aprset The poll structure we will be using.
  83. * @param numsock The number of sockets we are polling
  84. * @param nsds The number of sockets signalled.
  85. * @param timeout The amount of time in microseconds to wait. This is
  86. * a maximum, not a minimum. If a socket is signalled, we
  87. * will wake up before this time. A negative number means
  88. * wait until a socket is signalled.
  89. * @remark
  90. * <PRE>
  91. * The number of sockets signalled is returned in the second argument.
  92. *
  93. * This is a blocking call, and it will not return until either a
  94. * socket has been signalled, or the timeout has expired.
  95. * </PRE>
  96. }
  97. function apr_poll(aprset: Papr_pollfd_t; numsock: apr_int32_t;
  98. nsds: Papr_int32_t; timeout: apr_interval_time_t): apr_status_t;
  99. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  100. external LibAPR name LibNamePrefix + 'apr_poll' + LibSuff20;
  101. {
  102. * Add a socket to the poll structure.
  103. * @param aprset The poll structure we will be using.
  104. * @param sock The socket to add to the current poll structure.
  105. * @param event The events to look for when we do the poll. One of:
  106. * <PRE>
  107. * APR_POLLIN signal if read will not block
  108. * APR_POLLPRI signal if prioirty data is availble to be read
  109. * APR_POLLOUT signal if write will not block
  110. * </PRE>
  111. * @deprecated This function is deprecated, APR applications should control the pollset memory themselves.
  112. }
  113. function apr_poll_socket_add(aprset: Papr_pollfd_t; sock: Papr_socket_t;
  114. event: apr_int16_t): apr_status_t;
  115. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  116. external LibAPR name LibNamePrefix + 'apr_poll_socket_add' + LibSuff12;
  117. {
  118. * Modify a socket in the poll structure with mask.
  119. * @param aprset The poll structure we will be using.
  120. * @param sock The socket to modify in poll structure.
  121. * @param events The events to stop looking for during the poll. One of:
  122. * <PRE>
  123. * APR_POLLIN signal if read will not block
  124. * APR_POLLPRI signal if priority data is available to be read
  125. * APR_POLLOUT signal if write will not block
  126. * </PRE>
  127. * @deprecated This function is deprecated, APR applications should control the pollset memory themselves.
  128. }
  129. function apr_poll_socket_mask(aprset: Papr_pollfd_t; sock: Papr_socket_t;
  130. events: apr_int16_t): apr_status_t;
  131. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  132. external LibAPR name LibNamePrefix + 'apr_poll_socket_mask' + LibSuff12;
  133. {
  134. * Remove a socket from the poll structure.
  135. * @param aprset The poll structure we will be using.
  136. * @param sock The socket to remove from the current poll structure.
  137. * @deprecated This function is deprecated, APR applications should control the pollset memory themselves.
  138. }
  139. function apr_poll_socket_remove(aprset: Papr_pollfd_t; sock: Papr_socket_t): apr_status_t;
  140. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  141. external LibAPR name LibNamePrefix + 'apr_poll_socket_remove' + LibSuff8;
  142. {
  143. * Clear all events in the poll structure.
  144. * @param aprset The poll structure we will be using.
  145. * @param events The events to clear from all sockets. One of:
  146. * <PRE>
  147. * APR_POLLIN signal if read will not block
  148. * APR_POLLPRI signal if priority data is available to be read
  149. * APR_POLLOUT signal if write will not block
  150. * </PRE>
  151. * @deprecated This function is deprecated, APR applications should control the pollset memory themselves.
  152. }
  153. function apr_poll_socket_clear(aprset: Papr_pollfd_t;
  154. events: apr_int16_t): apr_status_t;
  155. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  156. external LibAPR name LibNamePrefix + 'apr_poll_socket_clear' + LibSuff8;
  157. {
  158. * Get the return events for the specified socket.
  159. * @param event The returned events for the socket. One of:
  160. * <PRE>
  161. * APR_POLLIN Data is available to be read
  162. * APR_POLLPRI Priority data is availble to be read
  163. * APR_POLLOUT Write will succeed
  164. * APR_POLLERR An error occurred on the socket
  165. * APR_POLLHUP The connection has been terminated
  166. * APR_POLLNVAL This is an invalid socket to poll on.
  167. * Socket not open.
  168. * </PRE>
  169. * @param sock The socket we wish to get information about.
  170. * @param aprset The poll structure we will be using.
  171. * @deprecated This function is deprecated, APR applications should control the pollset memory themselves.
  172. }
  173. function apr_poll_revents_get(event: Papr_int16_t; sock: Papr_socket_t;
  174. aprset: Papr_pollfd_t): apr_status_t;
  175. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  176. external LibAPR name LibNamePrefix + 'apr_poll_revents_get' + LibSuff12;
  177. { General-purpose poll API for arbitrarily large numbers of
  178. * file descriptors
  179. }
  180. { Opaque structure used for pollset API }
  181. type
  182. apr_pollset_t = record end;
  183. Papr_pollset_t = ^apr_pollset_t;
  184. PPapr_pollset_t = ^Papr_pollset_t;
  185. {
  186. * Setup a pollset object
  187. * @param pollset The pointer in which to return the newly created object
  188. * @param size The maximum number of descriptors that this pollset can hold
  189. * @param p The pool from which to allocate the pollset
  190. * @param flags Optional flags to modify the operation of the pollset
  191. * (reserved for future expansion)
  192. }
  193. function apr_pollset_create(pollset: PPapr_pollset_t; size: apr_uint32_tso_handle_t;
  194. p: Papr_pool_t; flags: apr_uint32_t): apr_status_t;
  195. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  196. external LibAPR name LibNamePrefix + 'apr_pollset_create' + LibSuff16;
  197. {
  198. * Destroy a pollset object
  199. * @param pollset The pollset to destroy
  200. }
  201. function apr_pollset_destroy(pollset: Papr_pollset_t): apr_status_t;
  202. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  203. external LibAPR name LibNamePrefix + 'apr_pollset_destroy' + LibSuff4;
  204. {
  205. * Add a socket or file descriptor to a pollset
  206. * @param pollset The pollset to which to add the descriptor
  207. * @param descriptor The descriptor to add
  208. * @remark If you set client_data in the descriptor, that value
  209. * will be returned in the client_data field whenever this
  210. * descriptor is signalled in apr_pollset_poll().
  211. }
  212. function apr_pollset_add(pollset: Papr_pollset_t;
  213. const descriptor: Papr_pollfd_t): apr_status_t;
  214. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  215. external LibAPR name LibNamePrefix + 'apr_pollset_add' + LibSuff8;
  216. {
  217. * Remove a descriptor from a pollset
  218. * @param pollset The pollset from which to remove the descriptor
  219. * @param descriptor The descriptor to remove
  220. }
  221. function apr_pollset_remove(pollset: Papr_pollset_t;
  222. const descriptor: Papr_pollfd_t): apr_status_t;
  223. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  224. external LibAPR name LibNamePrefix + 'apr_pollset_remove' + LibSuff8;
  225. {
  226. * Block for activity on the descriptor(s) in a pollset
  227. * @param pollset The pollset to use
  228. * @param timeout Timeout in microseconds
  229. * @param num Number of signalled descriptors (output parameter)
  230. * @param descriptors Array of signalled descriptors (output parameter)
  231. }
  232. function apr_pollset_poll(pollset: Papr_pollset_t; timeout: apr_interval_time_t;
  233. num: Papr_int32_t; const descriptors: PPapr_pollfd_t): apr_status_t;
  234. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  235. external LibAPR name LibNamePrefix + 'apr_pollset_poll' + LibSuff20;