apr_network_io.inc 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  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_network_io.h
  18. * @brief APR Network library
  19. }
  20. {#include "apr.h"
  21. #include "apr_pools.h"
  22. #include "apr_file_io.h"
  23. #include "apr_errno.h"
  24. #include "apr_inherit.h"
  25. #if APR_HAVE_NETINET_IN_H
  26. #include <netinet/in.h>
  27. #endif}
  28. {
  29. * @defgroup apr_network_io Network Routines
  30. * @ingroup APR
  31. }
  32. const
  33. { Maximum seconds to linger }
  34. APR_MAX_SECS_TO_LINGER = 30;
  35. { Maximum hostname length }
  36. APRMAXHOSTLEN = 256;
  37. { Default 'any' address }
  38. APR_ANYADDR = '0.0.0.0';
  39. {
  40. * @defgroup apr_sockopt Socket option definitions
  41. }
  42. APR_SO_LINGER = 1; {< Linger }
  43. APR_SO_KEEPALIVE = 2; {< Keepalive }
  44. APR_SO_DEBUG = 4; {< Debug }
  45. APR_SO_NONBLOCK = 8; {< Non-blocking IO }
  46. APR_SO_REUSEADDR = 16; {< Reuse addresses }
  47. APR_SO_SNDBUF = 64; {< Send buffer }
  48. APR_SO_RCVBUF = 128; {< Receive buffer }
  49. APR_SO_DISCONNECTED = 256; {< Disconnected }
  50. APR_TCP_NODELAY = 512; {< For SCTP sockets, this is mapped
  51. * to STCP_NODELAY internally.
  52. }
  53. APR_TCP_NOPUSH = 1024; {< No push }
  54. APR_RESET_NODELAY = 2048; {< This flag is ONLY set internally
  55. * when we set APR_TCP_NOPUSH with
  56. * APR_TCP_NODELAY set to tell us that
  57. * APR_TCP_NODELAY should be turned on
  58. * again when NOPUSH is turned off
  59. }
  60. APR_INCOMPLETE_READ = 4096; {< Set on non-blocking sockets
  61. * (timeout != 0) on which the
  62. * previous read() did not fill a buffer
  63. * completely. the next apr_socket_recv()
  64. * will first call select()/poll() rather than
  65. * going straight into read(). (Can also
  66. * be set by an application to force a
  67. * select()/poll() call before the next
  68. * read, in cases where the app expects
  69. * that an immediate read would fail.)
  70. }
  71. APR_INCOMPLETE_WRITE = 8192;{< like APR_INCOMPLETE_READ, but for write
  72. * @see APR_INCOMPLETE_READ
  73. }
  74. APR_IPV6_V6ONLY = 16384; {< Don't accept IPv4 connections on an
  75. * IPv6 listening socket.
  76. }
  77. APR_TCP_DEFER_ACCEPT = 32768;{< Delay accepting of new connections
  78. * until data is available.
  79. * @see apr_socket_accept_filter
  80. }
  81. { Define what type of socket shutdown should occur. }
  82. type
  83. apr_shutdown_how_e = (
  84. APR_SHUTDOWN_READ, {< no longer allow read request }
  85. APR_SHUTDOWN_WRITE, {< no longer allow write requests }
  86. APR_SHUTDOWN_READWRITE {< no longer allow read or write requests }
  87. );
  88. const
  89. APR_IPV4_ADDR_OK = $01; {< @see apr_sockaddr_info_get() }
  90. APR_IPV6_ADDR_OK = $02; {< @see apr_sockaddr_info_get() }
  91. {$ifndef APR_HAVE_IN_ADDR}
  92. {
  93. * We need to make sure we always have an in_addr type, so APR will just
  94. * define it ourselves, if the platform doesn't provide it.
  95. }
  96. {type
  97. in_addr = record
  98. s_addr: apr_uint32_t; < storage to hold the IP#
  99. end;}
  100. {$endif}
  101. { @def APR_INADDR_NONE
  102. * Not all platforms have a real INADDR_NONE. This macro replaces
  103. * INADDR_NONE on all platforms.
  104. }
  105. {$ifdef INADDR_NONE}
  106. APR_INADDR_NONE = INADDR_NONE;
  107. {$else}
  108. APR_INADDR_NONE = $ffffffff;
  109. {$endif}
  110. const
  111. {
  112. * @def APR_INET
  113. * Not all platforms have these defined, so we'll define them here
  114. * The default values come from FreeBSD 4.1.1
  115. }
  116. //#define APR_INET AF_INET
  117. { @def APR_UNSPEC
  118. * Let the system decide which address family to use
  119. }
  120. {#ifdef AF_UNSPEC
  121. #define APR_UNSPEC AF_UNSPEC
  122. #else
  123. #define APR_UNSPEC 0
  124. #endif
  125. #if APR_HAVE_IPV6
  126. /** @def APR_INET6
  127. * IPv6 Address Family. Not all platforms may have this defined.
  128. */
  129. #define APR_INET6 AF_INET6
  130. #endif}
  131. {
  132. * @defgroup IP_Proto IP Protocol Definitions for use when creating sockets
  133. }
  134. APR_PROTO_TCP = 6; {< TCP }
  135. APR_PROTO_UDP = 17; {< UDP }
  136. APR_PROTO_SCTP = 132; {< SCTP }
  137. {
  138. * Enum to tell us if we're interested in remote or local socket
  139. }
  140. type
  141. apr_interface_e = (
  142. APR_LOCAL,
  143. APR_REMOTE
  144. );
  145. {
  146. * The specific declaration of inet_addr's ... some platforms fall back
  147. * inet_network (this is not good, but necessary)
  148. }
  149. {$ifdef APR_HAVE_INET_ADDR}
  150. apr_inet_addr = inet_addr;
  151. {$else}
  152. {$ifdef APR_HAVE_INET_NETWORK} { only DGUX, as far as I know }
  153. {
  154. * @warning
  155. * not generally safe... inet_network() and inet_addr() perform
  156. * different functions }
  157. apr_inet_addr = inet_network;
  158. {$endif}
  159. {$endif}
  160. { A structure to represent sockets }
  161. apr_socket_t = record
  162. end;
  163. Papr_socket_t = ^apr_socket_t;
  164. PPapr_socket_t = ^Papr_socket_t;
  165. {
  166. * A structure to encapsulate headers and trailers for apr_socket_sendfile
  167. }
  168. Papr_hdtr_t = ^apr_hdtr_t;
  169. { A structure to represent in_addr }
  170. apr_in_addr_t = record
  171. end;
  172. { A structure to represent an IP subnet }
  173. apr_ipsubnet_t = record
  174. end;
  175. Papr_ipsubnet_t = ^apr_ipsubnet_t;
  176. PPapr_ipsubnet_t = ^Papr_ipsubnet_t;
  177. { @remark use apr_uint16_t just in case some system has a short that isn't 16 bits... }
  178. apr_port_t = apr_uint16_t;
  179. Papr_port_t = ^apr_port_t;
  180. { @remark It's defined here as I think it should all be platform safe...
  181. * @see apr_sockaddr_t
  182. }
  183. Papr_sockaddr_t = ^apr_sockaddr_t;
  184. PPapr_sockaddr_t = ^Papr_sockaddr_t;
  185. sa_t = record
  186. case Integer of
  187. { IPv4 sockaddr structure }
  188. 0: (sin: sockaddr_in);
  189. {$ifdef APR_HAVE_IPV6}
  190. { IPv6 sockaddr structure }
  191. 1: (sin6: sockaddr_in6);
  192. {$endif}
  193. {$ifdef APR_HAVE_SA_STORAGE}
  194. { Placeholder to ensure that the size of this union is not
  195. * dependent on whether APR_HAVE_IPV6 is defined. }
  196. 2: (sas: sockaddr_storage);
  197. {$endif}
  198. end;
  199. {
  200. * APRs socket address type, used to ensure protocol independence
  201. }
  202. apr_sockaddr_t = record
  203. { The pool to use... }
  204. pool: Papr_pool_t;
  205. { The hostname }
  206. hostname: PChar;
  207. { Either a string of the port number or the service name for the port }
  208. servname: PChar;
  209. { The numeric port }
  210. port: apr_port_t;
  211. { The family }
  212. family: apr_int32_t;
  213. { How big is the sockaddr we're using? }
  214. salen: apr_socklen_t;
  215. { How big is the ip address structure we're using? }
  216. ipaddr_len: cint;
  217. { How big should the address buffer be? 16 for v4 or 46 for v6
  218. * used in inet_ntop... }
  219. addr_str_len: cint;
  220. { This points to the IP address structure within the appropriate
  221. * sockaddr structure. }
  222. ipaddr_ptr: Pointer;
  223. { If multiple addresses were found by apr_sockaddr_info_get(), this
  224. * points to a representation of the next address. }
  225. next: Papr_sockaddr_t;
  226. { Union of either IPv4 or IPv6 sockaddr. }
  227. sa: sa_t;
  228. end;
  229. {$ifdef APR_HAS_SENDFILE}
  230. {
  231. * Support reusing the socket on platforms which support it (from disconnect,
  232. * specifically Win32.
  233. * @remark Optional flag passed into apr_socket_sendfile()
  234. }
  235. APR_SENDFILE_DISCONNECT_SOCKET = 1;
  236. {$endif}
  237. { A structure to encapsulate headers and trailers for apr_socket_sendfile }
  238. apr_hdtr_t = record
  239. { An iovec to store the headers sent before the file. }
  240. headers: Piovec;
  241. { number of headers in the iovec }
  242. numheaders: cint;
  243. { An iovec to store the trailers sent after the file. }
  244. trailers: Piovec;
  245. { number of trailers in the iovec }
  246. numtrailers: Integer;
  247. end;
  248. { function definitions }
  249. {
  250. * Create a socket.
  251. * @param new_sock The new socket that has been set up.
  252. * @param family The address family of the socket (e.g., APR_INET).
  253. * @param type The type of the socket (e.g., SOCK_STREAM).
  254. * @param cont The pool to use
  255. }
  256. function apr_socket_create(new_sock: PPapr_socket_t;
  257. family, type_, protocol: Integer; cont: Papr_pool_t): apr_status_t;
  258. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  259. external LibAPR name LibNamePrefix + 'apr_socket_create' + LibSuff20;
  260. {
  261. * Shutdown either reading, writing, or both sides of a socket.
  262. * @param thesocket The socket to close
  263. * @param how How to shutdown the socket. One of:
  264. * <PRE>
  265. * APR_SHUTDOWN_READ no longer allow read requests
  266. * APR_SHUTDOWN_WRITE no longer allow write requests
  267. * APR_SHUTDOWN_READWRITE no longer allow read or write requests
  268. * </PRE>
  269. * @see apr_shutdown_how_e
  270. * @remark This does not actually close the socket descriptor, it just
  271. * controls which calls are still valid on the socket.
  272. }
  273. function apr_socket_shutdown(thesocket: Papr_socket_t;
  274. how: apr_shutdown_how_e): apr_status_t;
  275. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  276. external LibAPR name LibNamePrefix + 'apr_socket_shutdown' + LibSuff8;
  277. {
  278. * Close a socket.
  279. * @param thesocket The socket to close
  280. }
  281. function apr_socket_close(thesocket: Papr_socket_t): apr_status_t;
  282. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  283. external LibAPR name LibNamePrefix + 'apr_socket_close' + LibSuff4;
  284. {
  285. * Bind the socket to its associated port
  286. * @param sock The socket to bind
  287. * @param sa The socket address to bind to
  288. * @remark This may be where we will find out if there is any other process
  289. * using the selected port.
  290. }
  291. function apr_socket_bind(sock: Papr_socket_t;
  292. sa: Papr_sockaddr_t): apr_status_t;
  293. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  294. external LibAPR name LibNamePrefix + 'apr_socket_bind' + LibSuff8;
  295. {
  296. * Listen to a bound socket for connections.
  297. * @param sock The socket to listen on
  298. * @param backlog The number of outstanding connections allowed in the sockets
  299. * listen queue. If this value is less than zero, the listen
  300. * queue size is set to zero.
  301. }
  302. function apr_socket_listen(sock: Papr_socket_t;
  303. backlog: apr_int32_t): apr_status_t;
  304. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  305. external LibAPR name LibNamePrefix + 'apr_socket_listen' + LibSuff8;
  306. {
  307. * Accept a new connection request
  308. * @param new_sock A copy of the socket that is connected to the socket that
  309. * made the connection request. This is the socket which should
  310. * be used for all future communication.
  311. * @param sock The socket we are listening on.
  312. * @param connection_pool The pool for the new socket.
  313. }
  314. function apr_socket_accept(new_sock: PPapr_socket_t;
  315. sock: Papr_socket_t; connection_pool: Papr_pool_t): apr_status_t;
  316. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  317. external LibAPR name LibNamePrefix + 'apr_socket_accept' + LibSuff12;
  318. {
  319. * Issue a connection request to a socket either on the same machine
  320. * or a different one.
  321. * @param sock The socket we wish to use for our side of the connection
  322. * @param sa The address of the machine we wish to connect to. If NULL,
  323. * APR assumes that the sockaddr_in in the apr_socket is
  324. * completely filled out.
  325. }
  326. function apr_socket_connect(sock: Papr_socket_t; sa: Papr_sockaddr_t): apr_status_t;
  327. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  328. external LibAPR name LibNamePrefix + 'apr_socket_connect' + LibSuff8;
  329. {
  330. * Create apr_sockaddr_t from hostname, address family, and port.
  331. * @param sa The new apr_sockaddr_t.
  332. * @param hostname The hostname or numeric address string to resolve/parse, or
  333. * NULL to build an address that corresponds to 0.0.0.0 or ::
  334. * @param family The address family to use, or APR_UNSPEC if the system should
  335. * decide.
  336. * @param port The port number.
  337. * @param flags Special processing flags:
  338. * <PRE>
  339. * APR_IPV4_ADDR_OK first query for IPv4 addresses; only look
  340. * for IPv6 addresses if the first query failed;
  341. * only valid if family is APR_UNSPEC and hostname
  342. * isn't NULL; mutually exclusive with
  343. * APR_IPV6_ADDR_OK
  344. * APR_IPV6_ADDR_OK first query for IPv6 addresses; only look
  345. * for IPv4 addresses if the first query failed;
  346. * only valid if family is APR_UNSPEC and hostname
  347. * isn't NULL and APR_HAVE_IPV6; mutually exclusive
  348. * with APR_IPV4_ADDR_OK
  349. * </PRE>
  350. * @param p The pool for the apr_sockaddr_t and associated storage.
  351. }
  352. function apr_sockaddr_info_get(sa: PPapr_socket_t;
  353. const hostname: PChar; family: apr_int32_t;
  354. port: apr_port_t; flags: apr_int32_t; p: Papr_pool_t): apr_status_t;
  355. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  356. external LibAPR name LibNamePrefix + 'apr_sockaddr_info_get' + LibSuff24;
  357. {
  358. * Look up the host name from an apr_sockaddr_t.
  359. * @param hostname The hostname.
  360. * @param sa The apr_sockaddr_t.
  361. * @param flags Special processing flags.
  362. }
  363. function apr_getnameinfo(hostname: PPChar; sa: Papr_socket_t; flags: apr_int32_t): apr_status_t;
  364. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  365. external LibAPR name LibNamePrefix + 'apr_getnameinfo' + LibSuff12;
  366. {
  367. * Parse hostname/IP address with scope id and port.
  368. *
  369. * Any of the following strings are accepted:
  370. * 8080 (just the port number)
  371. * www.apache.org (just the hostname)
  372. * www.apache.org:8080 (hostname and port number)
  373. * [fe80::1]:80 (IPv6 numeric address string only)
  374. * [fe80::1%eth0] (IPv6 numeric address string and scope id)
  375. *
  376. * Invalid strings:
  377. * (empty string)
  378. * [abc] (not valid IPv6 numeric address string)
  379. * abc:65536 (invalid port number)
  380. *
  381. * @param addr The new buffer containing just the hostname. On output, *addr
  382. * will be NULL if no hostname/IP address was specfied.
  383. * @param scope_id The new buffer containing just the scope id. On output,
  384. * *scope_id will be NULL if no scope id was specified.
  385. * @param port The port number. On output, *port will be 0 if no port was
  386. * specified.
  387. * ### FIXME: 0 is a legal port (per RFC 1700). this should
  388. * ### return something besides zero if the port is missing.
  389. * @param str The input string to be parsed.
  390. * @param p The pool from which *addr and *scope_id are allocated.
  391. * @remark If scope id shouldn't be allowed, check for scope_id != NULL in
  392. * addition to checking the return code. If addr/hostname should be
  393. * required, check for addr == NULL in addition to checking the
  394. * return code.
  395. }
  396. function apr_parse_addr_port(addr, scope_id: PPChar; port: Papr_port_t;
  397. const str: PChar; p: Papr_pool_t): apr_status_t;
  398. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  399. external LibAPR name LibNamePrefix + 'apr_parse_addr_port' + LibSuff20;
  400. {
  401. * Get name of the current machine
  402. * @param buf A buffer to store the hostname in.
  403. * @param len The maximum length of the hostname that can be stored in the
  404. * buffer provided. The suggested length is APRMAXHOSTLEN + 1.
  405. * @param cont The pool to use.
  406. * @remark If the buffer was not large enough, an error will be returned.
  407. }
  408. function apr_gethostname(buf: PChar; len: Integer; cont: Papr_pool_t): apr_status_t;
  409. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  410. external LibAPR name LibNamePrefix + 'apr_gethostname' + LibSuff12;
  411. {
  412. * Return the data associated with the current socket
  413. * @param data The user data associated with the socket.
  414. * @param key The key to associate with the user data.
  415. * @param sock The currently open socket.
  416. }
  417. function apr_socket_data_get(data: PPointer; const key: PChar;
  418. sock: Papr_sockaddr_t): apr_status_t;
  419. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  420. external LibAPR name LibNamePrefix + 'apr_socket_data_get' + LibSuff12;
  421. {
  422. * Set the data associated with the current socket.
  423. * @param sock The currently open socket.
  424. * @param data The user data to associate with the socket.
  425. * @param key The key to associate with the data.
  426. * @param cleanup The cleanup to call when the socket is destroyed.
  427. }
  428. type
  429. cleanup_t = function (param: Pointer): apr_status_t;
  430. function apr_socket_data_set(sock: Papr_socket_t; data: Pointer;
  431. const key: PChar; cleanup: cleanup_t): apr_status_t;
  432. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  433. external LibAPR name LibNamePrefix + 'apr_socket_data_set' + LibSuff16;
  434. {
  435. * Send data over a network.
  436. * @param sock The socket to send the data over.
  437. * @param buf The buffer which contains the data to be sent.
  438. * @param len On entry, the number of bytes to send; on exit, the number
  439. * of bytes sent.
  440. * @remark
  441. * <PRE>
  442. * This functions acts like a blocking write by default. To change
  443. * this behavior, use apr_socket_timeout_set().
  444. *
  445. * It is possible for both bytes to be sent and an error to be returned.
  446. *
  447. * APR_EINTR is never returned.
  448. * </PRE>
  449. }
  450. function apr_socket_send(sock: Papr_socket_t; const buf: PChar;
  451. len: Papr_size_t): apr_status_t;
  452. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  453. external LibAPR name LibNamePrefix + 'apr_socket_send' + LibSuff12;
  454. {
  455. * Send multiple packets of data over a network.
  456. * @param sock The socket to send the data over.
  457. * @param vec The array of iovec structs containing the data to send
  458. * @param nvec The number of iovec structs in the array
  459. * @param len Receives the number of bytes actually written
  460. * @remark
  461. * <PRE>
  462. * This functions acts like a blocking write by default. To change
  463. * this behavior, use apr_socket_timeout_set().
  464. * The number of bytes actually sent is stored in argument 3.
  465. *
  466. * It is possible for both bytes to be sent and an error to be returned.
  467. *
  468. * APR_EINTR is never returned.
  469. * </PRE>
  470. }
  471. function apr_socket_sendv(sock: Papr_socket_t; const vec: Piovec;
  472. nvec: apr_int32_t; len: Papr_size_t): apr_status_t;
  473. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  474. external LibAPR name LibNamePrefix + 'apr_socket_sendv' + LibSuff16;
  475. {
  476. * @param sock The socket to send from
  477. * @param where The apr_sockaddr_t describing where to send the data
  478. * @param flags The flags to use
  479. * @param buf The data to send
  480. * @param len The length of the data to send
  481. }
  482. function apr_socket_sendto(sock: Papr_socket_t; where: Papr_sockaddr_t;
  483. flags: apr_int32_t; const buf: PChar; len: Papr_size_t): apr_status_t;
  484. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  485. external LibAPR name LibNamePrefix + 'apr_socket_sendto' + LibSuff20;
  486. {
  487. * @param from The apr_sockaddr_t to fill in the recipient info
  488. * @param sock The socket to use
  489. * @param flags The flags to use
  490. * @param buf The buffer to use
  491. * @param len The length of the available buffer
  492. }
  493. function apr_socket_recvfrom(from: Papr_sockaddr_t; sock: Papr_socket_t;
  494. flags: apr_int32_t; buf: PChar; len: Papr_size_t): apr_status_t;
  495. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  496. external LibAPR name LibNamePrefix + 'apr_socket_recvfrom' + LibSuff20;
  497. {$if defined(APR_HAS_SENDFILE) or defined(DOXYGEN)}
  498. {
  499. * Send a file from an open file descriptor to a socket, along with
  500. * optional headers and trailers
  501. * @param sock The socket to which we're writing
  502. * @param file The open file from which to read
  503. * @param hdtr A structure containing the headers and trailers to send
  504. * @param offset Offset into the file where we should begin writing
  505. * @param len (input) - Number of bytes to send from the file
  506. * (output) - Number of bytes actually sent,
  507. * including headers, file, and trailers
  508. * @param flags APR flags that are mapped to OS specific flags
  509. * @remark This functions acts like a blocking write by default. To change
  510. * this behavior, use apr_socket_timeout_set().
  511. * The number of bytes actually sent is stored in argument 5.
  512. }
  513. function apr_socket_sendfile(sock: Papr_socket_t; file_: Papr_file_t;
  514. hdtr: Papr_hdtr_t; offset: Papr_off_t; len: Papr_size_t;
  515. flags: apr_int32_t): apr_status_t;
  516. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  517. external LibAPR name LibNamePrefix + 'apr_socket_sendfile' + LibSuff24;
  518. {$endif} { APR_HAS_SENDFILE }
  519. {
  520. * Read data from a network.
  521. * @param sock The socket to read the data from.
  522. * @param buf The buffer to store the data in.
  523. * @param len On entry, the number of bytes to receive; on exit, the number
  524. * of bytes received.
  525. * @remark
  526. * <PRE>
  527. * This functions acts like a blocking read by default. To change
  528. * this behavior, use apr_socket_timeout_set().
  529. * The number of bytes actually sent is stored in argument 3.
  530. *
  531. * It is possible for both bytes to be received and an APR_EOF or
  532. * other error to be returned.
  533. *
  534. * APR_EINTR is never returned.
  535. * </PRE>
  536. }
  537. function apr_socket_recv(sock: Papr_socket_t; buf: PChar; len: Papr_size_t): apr_status_t;
  538. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  539. external LibAPR name LibNamePrefix + 'apr_socket_recv' + LibSuff12;
  540. {
  541. * Setup socket options for the specified socket
  542. * @param sock The socket to set up.
  543. * @param opt The option we would like to configure. One of:
  544. * <PRE>
  545. * APR_SO_DEBUG -- turn on debugging information
  546. * APR_SO_KEEPALIVE -- keep connections active
  547. * APR_SO_LINGER -- lingers on close if data is present
  548. * APR_SO_NONBLOCK -- Turns blocking on/off for socket
  549. * When this option is enabled, use
  550. * the APR_STATUS_IS_EAGAIN() macro to
  551. * see if a send or receive function
  552. * could not transfer data without
  553. * blocking.
  554. * APR_SO_REUSEADDR -- The rules used in validating addresses
  555. * supplied to bind should allow reuse
  556. * of local addresses.
  557. * APR_SO_SNDBUF -- Set the SendBufferSize
  558. * APR_SO_RCVBUF -- Set the ReceiveBufferSize
  559. * </PRE>
  560. * @param on Value for the option.
  561. }
  562. function apr_socket_opt_set(sock: Papr_socket_t; opt, on_: apr_int32_t): apr_status_t;
  563. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  564. external LibAPR name LibNamePrefix + 'apr_socket_opt_set' + LibSuff12;
  565. {
  566. * Setup socket timeout for the specified socket
  567. * @param sock The socket to set up.
  568. * @param t Value for the timeout.
  569. * <PRE>
  570. * t > 0 -- read and write calls return APR_TIMEUP if specified time
  571. * elapsess with no data read or written
  572. * t == 0 -- read and write calls never block
  573. * t < 0 -- read and write calls block
  574. * </PRE>
  575. }
  576. function apr_socket_timeout_set(sock: Papr_socket_t; t: apr_interval_time_t): apr_status_t;
  577. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  578. external LibAPR name LibNamePrefix + 'apr_socket_timeout_set' + LibSuff12;
  579. {
  580. * Query socket options for the specified socket
  581. * @param sock The socket to query
  582. * @param opt The option we would like to query. One of:
  583. * <PRE>
  584. * APR_SO_DEBUG -- turn on debugging information
  585. * APR_SO_KEEPALIVE -- keep connections active
  586. * APR_SO_LINGER -- lingers on close if data is present
  587. * APR_SO_NONBLOCK -- Turns blocking on/off for socket
  588. * APR_SO_REUSEADDR -- The rules used in validating addresses
  589. * supplied to bind should allow reuse
  590. * of local addresses.
  591. * APR_SO_SNDBUF -- Set the SendBufferSize
  592. * APR_SO_RCVBUF -- Set the ReceiveBufferSize
  593. * APR_SO_DISCONNECTED -- Query the disconnected state of the socket.
  594. * (Currently only used on Windows)
  595. * </PRE>
  596. * @param on Socket option returned on the call.
  597. }
  598. function apr_socket_opt_get(sock: Papr_socket_t; opt, on_: apr_int32_t): apr_status_t;
  599. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  600. external LibAPR name LibNamePrefix + 'apr_socket_opt_get' + LibSuff12;
  601. {
  602. * Query socket timeout for the specified socket
  603. * @param sock The socket to query
  604. * @param t Socket timeout returned from the query.
  605. }
  606. function apr_socket_timeout_get(sock: Papr_socket_t; t: Papr_interval_time_t): apr_status_t;
  607. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  608. external LibAPR name LibNamePrefix + 'apr_socket_timeout_get' + LibSuff8;
  609. {
  610. * Query the specified socket if at the OOB/Urgent data mark
  611. * @param sock The socket to query
  612. * @param atmark Is set to true if socket is at the OOB/urgent mark,
  613. * otherwise is set to false.
  614. }
  615. function apr_socket_atmark(sock: Papr_socket_t; atmark: PInteger): apr_status_t;
  616. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  617. external LibAPR name LibNamePrefix + 'apr_socket_atmark' + LibSuff8;
  618. {
  619. * Return an apr_sockaddr_t from an apr_socket_t
  620. * @param sa The returned apr_sockaddr_t.
  621. * @param which Which interface do we want the apr_sockaddr_t for?
  622. * @param sock The socket to use
  623. }
  624. function apr_socket_addr_get(sa: PPapr_sockaddr_t;
  625. which: apr_interface_e; sock: Papr_socket_t): apr_status_t;
  626. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  627. external LibAPR name LibNamePrefix + 'apr_socket_addr_get' + LibSuff12;
  628. {
  629. * Return the IP address (in numeric address string format) in
  630. * an APR socket address. APR will allocate storage for the IP address
  631. * string from the pool of the apr_sockaddr_t.
  632. * @param addr The IP address.
  633. * @param sockaddr The socket address to reference.
  634. }
  635. function apr_sockaddr_ip_get(addr: PPChar; sockaddr: Papr_sockaddr_t): apr_status_t;
  636. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  637. external LibAPR name LibNamePrefix + 'apr_sockaddr_ip_get' + LibSuff8;
  638. {
  639. * See if the IP addresses in two APR socket addresses are
  640. * equivalent. Appropriate logic is present for comparing
  641. * IPv4-mapped IPv6 addresses with IPv4 addresses.
  642. *
  643. * @param addr1 One of the APR socket addresses.
  644. * @param addr2 The other APR socket address.
  645. * @remark The return value will be non-zero if the addresses
  646. * are equivalent.
  647. }
  648. function apr_sockaddr_equal(const addr1, addr2: Papr_sockaddr_t): Integer;
  649. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  650. external LibAPR name LibNamePrefix + 'apr_sockaddr_equal' + LibSuff8;
  651. {
  652. * Return the type of the socket.
  653. * @param sock The socket to query.
  654. * @param type The returned type (e.g., SOCK_STREAM).
  655. }
  656. function apr_socket_type_get(sock: Papr_socket_t; type_: PInteger): apr_status_t;
  657. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  658. external LibAPR name LibNamePrefix + 'apr_socket_type_get' + LibSuff8;
  659. {
  660. * Given an apr_sockaddr_t and a service name, set the port for the service
  661. * @param sockaddr The apr_sockaddr_t that will have its port set
  662. * @param servname The name of the service you wish to use
  663. }
  664. function apr_getservbyname(sockaddr: Papr_sockaddr_t; const servname: PChar): apr_status_t;
  665. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  666. external LibAPR name LibNamePrefix + 'apr_getservbyname' + LibSuff8;
  667. {
  668. * Build an ip-subnet representation from an IP address and optional netmask or
  669. * number-of-bits.
  670. * @param ipsub The new ip-subnet representation
  671. * @param ipstr The input IP address string
  672. * @param mask_or_numbits The input netmask or number-of-bits string, or NULL
  673. * @param p The pool to allocate from
  674. }
  675. function apr_ipsubnet_create(ipsub: PPapr_ipsubnet_t;
  676. const ipstr, mask_or_numbits: PChar; p: Papr_pool_t): apr_status_t;
  677. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  678. external LibAPR name LibNamePrefix + 'apr_ipsubnet_create' + LibSuff16;
  679. {
  680. * Test the IP address in an apr_sockaddr_t against a pre-built ip-subnet
  681. * representation.
  682. * @param ipsub The ip-subnet representation
  683. * @param sa The socket address to test
  684. * @return non-zero if the socket address is within the subnet, 0 otherwise
  685. }
  686. function apr_ipsubnet_test(ipsub: Papr_ipsubnet_t; sa: Papr_sockaddr_t): Integer;
  687. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  688. external LibAPR name LibNamePrefix + 'apr_ipsubnet_test' + LibSuff8;
  689. {$if defined(APR_HAS_SO_ACCEPTFILTER) or defined(DOXYGEN)}
  690. {
  691. * Set an OS level accept filter.
  692. * @param sock The socket to put the accept filter on.
  693. * @param name The accept filter
  694. * @param args Any extra args to the accept filter. Passing NULL here removes
  695. * the accept filter.
  696. }
  697. function apr_socket_accept_filter(sock: Papr_socket_t; name, args: PChar): apr_status_t;
  698. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  699. external LibAPR name LibNamePrefix + 'apr_socket_accept_filter' + LibSuff12;
  700. {$endif}
  701. {
  702. * Return the protocol of the socket.
  703. * @param sock The socket to query.
  704. * @param protocol The returned protocol (e.g., APR_PROTO_TCP).
  705. }
  706. function apr_socket_protocol_get(sock: Papr_socket_t; protocol: PInteger): apr_status_t;
  707. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  708. external LibAPR name LibNamePrefix + 'apr_socket_protocol_get' + LibSuff8;
  709. {
  710. * Get the pool used by the socket.
  711. }
  712. //APR_POOL_DECLARE_ACCESSOR(socket);
  713. {
  714. * Set a socket to be inherited by child processes.
  715. }
  716. //APR_DECLARE_INHERIT_SET(socket);
  717. {
  718. * Unset a socket from being inherited by child processes.
  719. }
  720. //APR_DECLARE_INHERIT_UNSET(socket);
  721. {
  722. * @defgroup apr_mcast IP Multicast
  723. }
  724. {
  725. * Join a Multicast Group
  726. * @param sock The socket to join a multicast group
  727. * @param join The address of the multicast group to join
  728. * @param iface Address of the interface to use. If NULL is passed, the
  729. * default multicast interface will be used. (OS Dependent)
  730. * @param source Source Address to accept transmissions from (non-NULL
  731. * implies Source-Specific Multicast)
  732. }
  733. function apr_mcast_join(sock: Papr_socket_t;
  734. join, iface, source: Papr_sockaddr_t): apr_status_t;
  735. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  736. external LibAPR name LibNamePrefix + 'apr_mcast_join' + LibSuff16;
  737. {
  738. * Leave a Multicast Group. All arguments must be the same as
  739. * apr_mcast_join.
  740. * @param sock The socket to leave a multicast group
  741. * @param addr The address of the multicast group to leave
  742. * @param iface Address of the interface to use. If NULL is passed, the
  743. * default multicast interface will be used. (OS Dependent)
  744. * @param source Source Address to accept transmissions from (non-NULL
  745. * implies Source-Specific Multicast)
  746. }
  747. function apr_mcast_leave(sock: Papr_socket_t;
  748. addr, iface, source: Papr_sockaddr_t): apr_status_t;
  749. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  750. external LibAPR name LibNamePrefix + 'apr_mcast_leave' + LibSuff16;
  751. {
  752. * Set the Multicast Time to Live (ttl) for a multicast transmission.
  753. * @param sock The socket to set the multicast ttl
  754. * @param ttl Time to live to Assign. 0-255, default=1
  755. * @remark If the TTL is 0, packets will only be seen by sockets on
  756. * the local machine, and only when multicast loopback is enabled.
  757. }
  758. function apr_mcast_hops(sock: Papr_socket_t; ttl: apr_byte_t): apr_status_t;
  759. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  760. external LibAPR name LibNamePrefix + 'apr_mcast_hops' + LibSuff8;
  761. {
  762. * Toggle IP Multicast Loopback
  763. * @param sock The socket to set multicast loopback
  764. * @param opt 0=disable, 1=enable
  765. }
  766. function apr_mcast_loopback(sock: Papr_socket_t; opt: apr_byte_t): apr_status_t;
  767. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  768. external LibAPR name LibNamePrefix + 'apr_mcast_loopback' + LibSuff8;
  769. {
  770. * Set the Interface to be used for outgoing Multicast Transmissions.
  771. * @param sock The socket to set the multicast interface on
  772. * @param iface Address of the interface to use for Multicast
  773. }
  774. function apr_mcast_interface(sock: Papr_socket_t; iface: Papr_sockaddr_t): apr_status_t;
  775. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  776. external LibAPR name LibNamePrefix + 'apr_mcast_interface' + LibSuff8;