home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / apache_2.2.8-win32-x86-no_ssl.msi / Data1.cab / _22F1906AA15A5024B44CE15255F8BFB8 < prev    next >
Text File  |  2007-10-15  |  33KB  |  831 lines

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