apr_network_io.inc 34 KB

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