Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

apr_network_io.h

Go to the documentation of this file.
00001 /* Copyright 2000-2004 The Apache Software Foundation
00002  *
00003  * Licensed under the Apache License, Version 2.0 (the "License");
00004  * you may not use this file except in compliance with the License.
00005  * You may obtain a copy of the License at
00006  *
00007  *     http://www.apache.org/licenses/LICENSE-2.0
00008  *
00009  * Unless required by applicable law or agreed to in writing, software
00010  * distributed under the License is distributed on an "AS IS" BASIS,
00011  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012  * See the License for the specific language governing permissions and
00013  * limitations under the License.
00014  */
00015 
00016 #ifndef APR_NETWORK_IO_H
00017 #define APR_NETWORK_IO_H
00018 /**
00019  * @file apr_network_io.h
00020  * @brief APR Network library
00021  */
00022 
00023 #include "apr.h"
00024 #include "apr_pools.h"
00025 #include "apr_file_io.h"
00026 #include "apr_errno.h"
00027 #include "apr_inherit.h" 
00028 
00029 #if APR_HAVE_NETINET_IN_H
00030 #include <netinet/in.h>
00031 #endif
00032 
00033 #ifdef __cplusplus
00034 extern "C" {
00035 #endif /* __cplusplus */
00036 
00037 /**
00038  * @defgroup apr_network_io Network Routines
00039  * @ingroup APR 
00040  * @{
00041  */
00042 
00043 #ifndef APR_MAX_SECS_TO_LINGER
00044 /** Maximum seconds to linger */
00045 #define APR_MAX_SECS_TO_LINGER 30
00046 #endif
00047 
00048 #ifndef APRMAXHOSTLEN
00049 /** Maximum hostname length */
00050 #define APRMAXHOSTLEN 256
00051 #endif
00052 
00053 #ifndef APR_ANYADDR
00054 /** Default 'any' address */
00055 #define APR_ANYADDR "0.0.0.0"
00056 #endif
00057 
00058 /**
00059  * @defgroup apr_sockopt Socket option definitions
00060  * @{
00061  */
00062 #define APR_SO_LINGER        1    /**< Linger */
00063 #define APR_SO_KEEPALIVE     2    /**< Keepalive */
00064 #define APR_SO_DEBUG         4    /**< Debug */
00065 #define APR_SO_NONBLOCK      8    /**< Non-blocking IO */
00066 #define APR_SO_REUSEADDR     16   /**< Reuse addresses */
00067 #define APR_SO_SNDBUF        64   /**< Send buffer */
00068 #define APR_SO_RCVBUF        128  /**< Receive buffer */
00069 #define APR_SO_DISCONNECTED  256  /**< Disconnected */
00070 #define APR_TCP_NODELAY      512  /**< For SCTP sockets, this is mapped
00071                                    * to STCP_NODELAY internally.
00072                                    */
00073 #define APR_TCP_NOPUSH       1024 /**< No push */
00074 #define APR_RESET_NODELAY    2048 /**< This flag is ONLY set internally
00075                                    * when we set APR_TCP_NOPUSH with
00076                                    * APR_TCP_NODELAY set to tell us that
00077                                    * APR_TCP_NODELAY should be turned on
00078                                    * again when NOPUSH is turned off
00079                                    */
00080 #define APR_INCOMPLETE_READ 4096  /**< Set on non-blocking sockets
00081                                    * (timeout != 0) on which the
00082                                    * previous read() did not fill a buffer
00083                                    * completely.  the next apr_socket_recv() 
00084                                    * will first call select()/poll() rather than
00085                                    * going straight into read().  (Can also
00086                                    * be set by an application to force a
00087                                    * select()/poll() call before the next
00088                                    * read, in cases where the app expects
00089                                    * that an immediate read would fail.)
00090                                    */
00091 #define APR_INCOMPLETE_WRITE 8192 /**< like APR_INCOMPLETE_READ, but for write
00092                                    * @see APR_INCOMPLETE_READ
00093                                    */
00094 #define APR_IPV6_V6ONLY     16384 /**< Don't accept IPv4 connections on an
00095                                    * IPv6 listening socket.
00096                                    */
00097 #define APR_TCP_DEFER_ACCEPT 32768 /**< Delay accepting of new connections 
00098                                     * until data is available.
00099                                     * @see apr_socket_accept_filter
00100                                     */
00101 
00102 /** @} */
00103 
00104 /** Define what type of socket shutdown should occur. */
00105 typedef enum {
00106     APR_SHUTDOWN_READ,          /**< no longer allow read request */
00107     APR_SHUTDOWN_WRITE,         /**< no longer allow write requests */
00108     APR_SHUTDOWN_READWRITE      /**< no longer allow read or write requests */
00109 } apr_shutdown_how_e;
00110 
00111 #define APR_IPV4_ADDR_OK  0x01  /**< @see apr_sockaddr_info_get() */
00112 #define APR_IPV6_ADDR_OK  0x02  /**< @see apr_sockaddr_info_get() */
00113 
00114 #if (!APR_HAVE_IN_ADDR)
00115 /**
00116  * We need to make sure we always have an in_addr type, so APR will just
00117  * define it ourselves, if the platform doesn't provide it.
00118  */
00119 struct in_addr {
00120     apr_uint32_t  s_addr; /**< storage to hold the IP# */
00121 };
00122 #endif
00123 
00124 /** @def APR_INADDR_NONE
00125  * Not all platforms have a real INADDR_NONE.  This macro replaces
00126  * INADDR_NONE on all platforms.
00127  */
00128 #ifdef INADDR_NONE
00129 #define APR_INADDR_NONE INADDR_NONE
00130 #else
00131 #define APR_INADDR_NONE ((unsigned int) 0xffffffff)
00132 #endif
00133 
00134 /**
00135  * @def APR_INET
00136  * Not all platforms have these defined, so we'll define them here
00137  * The default values come from FreeBSD 4.1.1
00138  */
00139 #define APR_INET     AF_INET
00140 /** @def APR_UNSPEC
00141  * Let the system decide which address family to use
00142  */
00143 #ifdef AF_UNSPEC
00144 #define APR_UNSPEC   AF_UNSPEC
00145 #else
00146 #define APR_UNSPEC   0
00147 #endif
00148 #if APR_HAVE_IPV6
00149 /** @def APR_INET6
00150 * IPv6 Address Family. Not all platforms may have this defined.
00151 */
00152 
00153 #define APR_INET6    AF_INET6
00154 #endif
00155 
00156 /**
00157  * @defgroup IP_Proto IP Protocol Definitions for use when creating sockets
00158  * @{
00159  */
00160 #define APR_PROTO_TCP       6   /**< TCP  */
00161 #define APR_PROTO_UDP      17   /**< UDP  */
00162 #define APR_PROTO_SCTP    132   /**< SCTP */
00163 /** @} */
00164 
00165 /**
00166  * Enum to tell us if we're interested in remote or local socket
00167  */
00168 typedef enum {
00169     APR_LOCAL,
00170     APR_REMOTE
00171 } apr_interface_e;
00172 
00173 /**
00174  * The specific declaration of inet_addr's ... some platforms fall back
00175  * inet_network (this is not good, but necessary)
00176  */
00177 
00178 #if APR_HAVE_INET_ADDR
00179 #define apr_inet_addr    inet_addr
00180 #elif APR_HAVE_INET_NETWORK        /* only DGUX, as far as I know */
00181 /**
00182  * @warning
00183  * not generally safe... inet_network() and inet_addr() perform
00184  * different functions */
00185 #define apr_inet_addr    inet_network
00186 #endif
00187 
00188 /** A structure to represent sockets */
00189 typedef struct apr_socket_t     apr_socket_t;
00190 /**
00191  * A structure to encapsulate headers and trailers for apr_socket_sendfile
00192  */
00193 typedef struct apr_hdtr_t       apr_hdtr_t;
00194 /** A structure to represent in_addr */
00195 typedef struct in_addr          apr_in_addr_t;
00196 /** A structure to represent an IP subnet */
00197 typedef struct apr_ipsubnet_t apr_ipsubnet_t;
00198 
00199 /** @remark use apr_uint16_t just in case some system has a short that isn't 16 bits... */
00200 typedef apr_uint16_t            apr_port_t;
00201 
00202 /** @remark It's defined here as I think it should all be platform safe...
00203  * @see apr_sockaddr_t
00204  */
00205 typedef struct apr_sockaddr_t apr_sockaddr_t;
00206 /**
00207  * APRs socket address type, used to ensure protocol independence
00208  */
00209 struct apr_sockaddr_t {
00210     /** The pool to use... */
00211     apr_pool_t *pool;
00212     /** The hostname */
00213     char *hostname;
00214     /** Either a string of the port number or the service name for the port */
00215     char *servname;
00216     /** The numeric port */
00217     apr_port_t port;
00218     /** The family */
00219     apr_int32_t family;
00220     /** How big is the sockaddr we're using? */
00221     apr_socklen_t salen;
00222     /** How big is the ip address structure we're using? */
00223     int ipaddr_len;
00224     /** How big should the address buffer be?  16 for v4 or 46 for v6
00225      *  used in inet_ntop... */
00226     int addr_str_len;
00227     /** This points to the IP address structure within the appropriate
00228      *  sockaddr structure.  */
00229     void *ipaddr_ptr;
00230     /** If multiple addresses were found by apr_sockaddr_info_get(), this 
00231      *  points to a representation of the next address. */
00232     apr_sockaddr_t *next;
00233     /** Union of either IPv4 or IPv6 sockaddr. */
00234     union {
00235         /** IPv4 sockaddr structure */
00236         struct sockaddr_in sin;
00237 #if APR_HAVE_IPV6
00238         /** IPv6 sockaddr structure */
00239         struct sockaddr_in6 sin6;
00240 #endif
00241 #if APR_HAVE_SA_STORAGE
00242         /** Placeholder to ensure that the size of this union is not
00243          * dependent on whether APR_HAVE_IPV6 is defined. */
00244         struct sockaddr_storage sas;
00245 #endif
00246     } sa;
00247 };
00248 
00249 #if APR_HAS_SENDFILE
00250 /** 
00251  * Support reusing the socket on platforms which support it (from disconnect,
00252  * specifically Win32.
00253  * @remark Optional flag passed into apr_socket_sendfile() 
00254  */
00255 #define APR_SENDFILE_DISCONNECT_SOCKET      1
00256 #endif
00257 
00258 /** A structure to encapsulate headers and trailers for apr_socket_sendfile */
00259 struct apr_hdtr_t {
00260     /** An iovec to store the headers sent before the file. */
00261     struct iovec* headers;
00262     /** number of headers in the iovec */
00263     int numheaders;
00264     /** An iovec to store the trailers sent after the file. */
00265     struct iovec* trailers;
00266     /** number of trailers in the iovec */
00267     int numtrailers;
00268 };
00269 
00270 /* function definitions */
00271 
00272 /**
00273  * Create a socket.
00274  * @param new_sock The new socket that has been set up.
00275  * @param family The address family of the socket (e.g., APR_INET).
00276  * @param type The type of the socket (e.g., SOCK_STREAM).
00277  * @param protocol The protocol of the socket (e.g., APR_PROTO_TCP).
00278  * @param cont The pool to use
00279  */
00280 APR_DECLARE(apr_status_t) apr_socket_create(apr_socket_t **new_sock, 
00281                                             int family, int type,
00282                                             int protocol,
00283                                             apr_pool_t *cont);
00284 
00285 /**
00286  * Shutdown either reading, writing, or both sides of a socket.
00287  * @param thesocket The socket to close 
00288  * @param how How to shutdown the socket.  One of:
00289  * <PRE>
00290  *            APR_SHUTDOWN_READ         no longer allow read requests
00291  *            APR_SHUTDOWN_WRITE        no longer allow write requests
00292  *            APR_SHUTDOWN_READWRITE    no longer allow read or write requests 
00293  * </PRE>
00294  * @see apr_shutdown_how_e
00295  * @remark This does not actually close the socket descriptor, it just
00296  *      controls which calls are still valid on the socket.
00297  */
00298 APR_DECLARE(apr_status_t) apr_socket_shutdown(apr_socket_t *thesocket,
00299                                               apr_shutdown_how_e how);
00300 
00301 /**
00302  * Close a socket.
00303  * @param thesocket The socket to close 
00304  */
00305 APR_DECLARE(apr_status_t) apr_socket_close(apr_socket_t *thesocket);
00306 
00307 /**
00308  * Bind the socket to its associated port
00309  * @param sock The socket to bind 
00310  * @param sa The socket address to bind to
00311  * @remark This may be where we will find out if there is any other process
00312  *      using the selected port.
00313  */
00314 APR_DECLARE(apr_status_t) apr_socket_bind(apr_socket_t *sock, 
00315                                           apr_sockaddr_t *sa);
00316 
00317 /**
00318  * Listen to a bound socket for connections.
00319  * @param sock The socket to listen on 
00320  * @param backlog The number of outstanding connections allowed in the sockets
00321  *                listen queue.  If this value is less than zero, the listen
00322  *                queue size is set to zero.  
00323  */
00324 APR_DECLARE(apr_status_t) apr_socket_listen(apr_socket_t *sock, 
00325                                             apr_int32_t backlog);
00326 
00327 /**
00328  * Accept a new connection request
00329  * @param new_sock A copy of the socket that is connected to the socket that
00330  *                 made the connection request.  This is the socket which should
00331  *                 be used for all future communication.
00332  * @param sock The socket we are listening on.
00333  * @param connection_pool The pool for the new socket.
00334  */
00335 APR_DECLARE(apr_status_t) apr_socket_accept(apr_socket_t **new_sock, 
00336                                             apr_socket_t *sock,
00337                                             apr_pool_t *connection_pool);
00338 
00339 /**
00340  * Issue a connection request to a socket either on the same machine 
00341  * or a different one.
00342  * @param sock The socket we wish to use for our side of the connection 
00343  * @param sa The address of the machine we wish to connect to.
00344  */
00345 APR_DECLARE(apr_status_t) apr_socket_connect(apr_socket_t *sock,
00346                                              apr_sockaddr_t *sa);
00347 
00348 /**
00349  * Create apr_sockaddr_t from hostname, address family, and port.
00350  * @param sa The new apr_sockaddr_t.
00351  * @param hostname The hostname or numeric address string to resolve/parse, or
00352  *               NULL to build an address that corresponds to 0.0.0.0 or ::
00353  * @param family The address family to use, or APR_UNSPEC if the system should 
00354  *               decide.
00355  * @param port The port number.
00356  * @param flags Special processing flags:
00357  * <PRE>
00358  *       APR_IPV4_ADDR_OK          first query for IPv4 addresses; only look
00359  *                                 for IPv6 addresses if the first query failed;
00360  *                                 only valid if family is APR_UNSPEC and hostname
00361  *                                 isn't NULL; mutually exclusive with
00362  *                                 APR_IPV6_ADDR_OK
00363  *       APR_IPV6_ADDR_OK          first query for IPv6 addresses; only look
00364  *                                 for IPv4 addresses if the first query failed;
00365  *                                 only valid if family is APR_UNSPEC and hostname
00366  *                                 isn't NULL and APR_HAVE_IPV6; mutually exclusive
00367  *                                 with APR_IPV4_ADDR_OK
00368  * </PRE>
00369  * @param p The pool for the apr_sockaddr_t and associated storage.
00370  */
00371 APR_DECLARE(apr_status_t) apr_sockaddr_info_get(apr_sockaddr_t **sa,
00372                                           const char *hostname,
00373                                           apr_int32_t family,
00374                                           apr_port_t port,
00375                                           apr_int32_t flags,
00376                                           apr_pool_t *p);
00377 
00378 /**
00379  * Look up the host name from an apr_sockaddr_t.
00380  * @param hostname The hostname.
00381  * @param sa The apr_sockaddr_t.
00382  * @param flags Special processing flags.
00383  */
00384 APR_DECLARE(apr_status_t) apr_getnameinfo(char **hostname,
00385                                           apr_sockaddr_t *sa,
00386                                           apr_int32_t flags);
00387 
00388 /**
00389  * Parse hostname/IP address with scope id and port.
00390  *
00391  * Any of the following strings are accepted:
00392  *   8080                  (just the port number)
00393  *   www.apache.org        (just the hostname)
00394  *   www.apache.org:8080   (hostname and port number)
00395  *   [fe80::1]:80          (IPv6 numeric address string only)
00396  *   [fe80::1%eth0]        (IPv6 numeric address string and scope id)
00397  *
00398  * Invalid strings:
00399  *                         (empty string)
00400  *   [abc]                 (not valid IPv6 numeric address string)
00401  *   abc:65536             (invalid port number)
00402  *
00403  * @param addr The new buffer containing just the hostname.  On output, *addr 
00404  *             will be NULL if no hostname/IP address was specfied.
00405  * @param scope_id The new buffer containing just the scope id.  On output, 
00406  *                 *scope_id will be NULL if no scope id was specified.
00407  * @param port The port number.  On output, *port will be 0 if no port was 
00408  *             specified.
00409  *             ### FIXME: 0 is a legal port (per RFC 1700). this should
00410  *             ### return something besides zero if the port is missing.
00411  * @param str The input string to be parsed.
00412  * @param p The pool from which *addr and *scope_id are allocated.
00413  * @remark If scope id shouldn't be allowed, check for scope_id != NULL in 
00414  *         addition to checking the return code.  If addr/hostname should be 
00415  *         required, check for addr == NULL in addition to checking the 
00416  *         return code.
00417  */
00418 APR_DECLARE(apr_status_t) apr_parse_addr_port(char **addr,
00419                                               char **scope_id,
00420                                               apr_port_t *port,
00421                                               const char *str,
00422                                               apr_pool_t *p);
00423 
00424 /**
00425  * Get name of the current machine
00426  * @param buf A buffer to store the hostname in.
00427  * @param len The maximum length of the hostname that can be stored in the
00428  *            buffer provided.  The suggested length is APRMAXHOSTLEN + 1.
00429  * @param cont The pool to use.
00430  * @remark If the buffer was not large enough, an error will be returned.
00431  */
00432 APR_DECLARE(apr_status_t) apr_gethostname(char *buf, int len, apr_pool_t *cont);
00433 
00434 /**
00435  * Return the data associated with the current socket
00436  * @param data The user data associated with the socket.
00437  * @param key The key to associate with the user data.
00438  * @param sock The currently open socket.
00439  */
00440 APR_DECLARE(apr_status_t) apr_socket_data_get(void **data, const char *key,
00441                                               apr_socket_t *sock);
00442 
00443 /**
00444  * Set the data associated with the current socket.
00445  * @param sock The currently open socket.
00446  * @param data The user data to associate with the socket.
00447  * @param key The key to associate with the data.
00448  * @param cleanup The cleanup to call when the socket is destroyed.
00449  */
00450 APR_DECLARE(apr_status_t) apr_socket_data_set(apr_socket_t *sock, void *data,
00451                                               const char *key,
00452                                               apr_status_t (*cleanup)(void*));
00453 
00454 /**
00455  * Send data over a network.
00456  * @param sock The socket to send the data over.
00457  * @param buf The buffer which contains the data to be sent. 
00458  * @param len On entry, the number of bytes to send; on exit, the number
00459  *            of bytes sent.
00460  * @remark
00461  * <PRE>
00462  * This functions acts like a blocking write by default.  To change 
00463  * this behavior, use apr_socket_timeout_set() or the APR_SO_NONBLOCK
00464  * socket option.
00465  *
00466  * It is possible for both bytes to be sent and an error to be returned.
00467  *
00468  * APR_EINTR is never returned.
00469  * </PRE>
00470  */
00471 APR_DECLARE(apr_status_t) apr_socket_send(apr_socket_t *sock, const char *buf, 
00472                                           apr_size_t *len);
00473 
00474 /**
00475  * Send multiple packets of data over a network.
00476  * @param sock The socket to send the data over.
00477  * @param vec The array of iovec structs containing the data to send 
00478  * @param nvec The number of iovec structs in the array
00479  * @param len Receives the number of bytes actually written
00480  * @remark
00481  * <PRE>
00482  * This functions acts like a blocking write by default.  To change 
00483  * this behavior, use apr_socket_timeout_set() or the APR_SO_NONBLOCK
00484  * socket option.
00485  * The number of bytes actually sent is stored in argument 3.
00486  *
00487  * It is possible for both bytes to be sent and an error to be returned.
00488  *
00489  * APR_EINTR is never returned.
00490  * </PRE>
00491  */
00492 APR_DECLARE(apr_status_t) apr_socket_sendv(apr_socket_t *sock, 
00493                                            const struct iovec *vec,
00494                                            apr_int32_t nvec, apr_size_t *len);
00495 
00496 /**
00497  * @param sock The socket to send from
00498  * @param where The apr_sockaddr_t describing where to send the data
00499  * @param flags The flags to use
00500  * @param buf  The data to send
00501  * @param len  The length of the data to send
00502  */
00503 APR_DECLARE(apr_status_t) apr_socket_sendto(apr_socket_t *sock, 
00504                                             apr_sockaddr_t *where,
00505                                             apr_int32_t flags, const char *buf, 
00506                                             apr_size_t *len);
00507 
00508 /**
00509  * @param from The apr_sockaddr_t to fill in the recipient info
00510  * @param sock The socket to use
00511  * @param flags The flags to use
00512  * @param buf  The buffer to use
00513  * @param len  The length of the available buffer
00514  */
00515 
00516 APR_DECLARE(apr_status_t) apr_socket_recvfrom(apr_sockaddr_t *from, 
00517                                               apr_socket_t *sock,
00518                                               apr_int32_t flags, char *buf, 
00519                                               apr_size_t *len);
00520  
00521 #if APR_HAS_SENDFILE || defined(DOXYGEN)
00522 
00523 /**
00524  * Send a file from an open file descriptor to a socket, along with 
00525  * optional headers and trailers
00526  * @param sock The socket to which we're writing
00527  * @param file The open file from which to read
00528  * @param hdtr A structure containing the headers and trailers to send
00529  * @param offset Offset into the file where we should begin writing
00530  * @param len (input)  - Number of bytes to send from the file 
00531  *            (output) - Number of bytes actually sent, 
00532  *                       including headers, file, and trailers
00533  * @param flags APR flags that are mapped to OS specific flags
00534  * @remark This functions acts like a blocking write by default.  To change 
00535  *         this behavior, use apr_socket_timeout_set() or the
00536  *         APR_SO_NONBLOCK socket option.
00537  * The number of bytes actually sent is stored in the len parameter.
00538  * The offset parameter is passed by reference for no reason; its
00539  * value will never be modified by the apr_socket_sendfile() function.
00540  */
00541 APR_DECLARE(apr_status_t) apr_socket_sendfile(apr_socket_t *sock, 
00542                                               apr_file_t *file,
00543                                               apr_hdtr_t *hdtr,
00544                                               apr_off_t *offset,
00545                                               apr_size_t *len,
00546                                               apr_int32_t flags);
00547 
00548 #endif /* APR_HAS_SENDFILE */
00549 
00550 /**
00551  * Read data from a network.
00552  * @param sock The socket to read the data from.
00553  * @param buf The buffer to store the data in. 
00554  * @param len On entry, the number of bytes to receive; on exit, the number
00555  *            of bytes received.
00556  * @remark
00557  * <PRE>
00558  * This functions acts like a blocking read by default.  To change 
00559  * this behavior, use apr_socket_timeout_set() or the APR_SO_NONBLOCK
00560  * socket option.
00561  * The number of bytes actually received is stored in argument 3.
00562  *
00563  * It is possible for both bytes to be received and an APR_EOF or
00564  * other error to be returned.
00565  *
00566  * APR_EINTR is never returned.
00567  * </PRE>
00568  */
00569 APR_DECLARE(apr_status_t) apr_socket_recv(apr_socket_t *sock, 
00570                                    char *buf, apr_size_t *len);
00571 
00572 /**
00573  * Setup socket options for the specified socket
00574  * @param sock The socket to set up.
00575  * @param opt The option we would like to configure.  One of:
00576  * <PRE>
00577  *            APR_SO_DEBUG      --  turn on debugging information 
00578  *            APR_SO_KEEPALIVE  --  keep connections active
00579  *            APR_SO_LINGER     --  lingers on close if data is present
00580  *            APR_SO_NONBLOCK   --  Turns blocking on/off for socket
00581  *                                  When this option is enabled, use
00582  *                                  the APR_STATUS_IS_EAGAIN() macro to
00583  *                                  see if a send or receive function
00584  *                                  could not transfer data without
00585  *                                  blocking.
00586  *            APR_SO_REUSEADDR  --  The rules used in validating addresses
00587  *                                  supplied to bind should allow reuse
00588  *                                  of local addresses.
00589  *            APR_SO_SNDBUF     --  Set the SendBufferSize
00590  *            APR_SO_RCVBUF     --  Set the ReceiveBufferSize
00591  * </PRE>
00592  * @param on Value for the option.
00593  */
00594 APR_DECLARE(apr_status_t) apr_socket_opt_set(apr_socket_t *sock,
00595                                              apr_int32_t opt, apr_int32_t on);
00596 
00597 /**
00598  * Setup socket timeout for the specified socket
00599  * @param sock The socket to set up.
00600  * @param t Value for the timeout.
00601  * <PRE>
00602  *   t > 0  -- read and write calls return APR_TIMEUP if specified time
00603  *             elapsess with no data read or written
00604  *   t == 0 -- read and write calls never block
00605  *   t < 0  -- read and write calls block
00606  * </PRE>
00607  */
00608 APR_DECLARE(apr_status_t) apr_socket_timeout_set(apr_socket_t *sock,
00609                                                  apr_interval_time_t t);
00610 
00611 /**
00612  * Query socket options for the specified socket
00613  * @param sock The socket to query
00614  * @param opt The option we would like to query.  One of:
00615  * <PRE>
00616  *            APR_SO_DEBUG      --  turn on debugging information 
00617  *            APR_SO_KEEPALIVE  --  keep connections active
00618  *            APR_SO_LINGER     --  lingers on close if data is present
00619  *            APR_SO_NONBLOCK   --  Turns blocking on/off for socket
00620  *            APR_SO_REUSEADDR  --  The rules used in validating addresses
00621  *                                  supplied to bind should allow reuse
00622  *                                  of local addresses.
00623  *            APR_SO_SNDBUF     --  Set the SendBufferSize
00624  *            APR_SO_RCVBUF     --  Set the ReceiveBufferSize
00625  *            APR_SO_DISCONNECTED -- Query the disconnected state of the socket.
00626  *                                  (Currently only used on Windows)
00627  * </PRE>
00628  * @param on Socket option returned on the call.
00629  */
00630 APR_DECLARE(apr_status_t) apr_socket_opt_get(apr_socket_t *sock, 
00631                                              apr_int32_t opt, apr_int32_t *on);
00632 
00633 /**
00634  * Query socket timeout for the specified socket
00635  * @param sock The socket to query
00636  * @param t Socket timeout returned from the query.
00637  */
00638 APR_DECLARE(apr_status_t) apr_socket_timeout_get(apr_socket_t *sock, 
00639                                                  apr_interval_time_t *t);
00640 
00641 /**
00642  * Query the specified socket if at the OOB/Urgent data mark
00643  * @param sock The socket to query
00644  * @param atmark Is set to true if socket is at the OOB/urgent mark,
00645  *               otherwise is set to false.
00646  */
00647 APR_DECLARE(apr_status_t) apr_socket_atmark(apr_socket_t *sock, 
00648                                             int *atmark);
00649 
00650 /**
00651  * Return an apr_sockaddr_t from an apr_socket_t
00652  * @param sa The returned apr_sockaddr_t.
00653  * @param which Which interface do we want the apr_sockaddr_t for?
00654  * @param sock The socket to use
00655  */
00656 APR_DECLARE(apr_status_t) apr_socket_addr_get(apr_sockaddr_t **sa,
00657                                               apr_interface_e which,
00658                                               apr_socket_t *sock);
00659  
00660 /**
00661  * Return the IP address (in numeric address string format) in
00662  * an APR socket address.  APR will allocate storage for the IP address 
00663  * string from the pool of the apr_sockaddr_t.
00664  * @param addr The IP address.
00665  * @param sockaddr The socket address to reference.
00666  */
00667 APR_DECLARE(apr_status_t) apr_sockaddr_ip_get(char **addr, 
00668                                               apr_sockaddr_t *sockaddr);
00669 
00670 /**
00671  * See if the IP addresses in two APR socket addresses are
00672  * equivalent.  Appropriate logic is present for comparing
00673  * IPv4-mapped IPv6 addresses with IPv4 addresses.
00674  *
00675  * @param addr1 One of the APR socket addresses.
00676  * @param addr2 The other APR socket address.
00677  * @remark The return value will be non-zero if the addresses
00678  * are equivalent.
00679  */
00680 APR_DECLARE(int) apr_sockaddr_equal(const apr_sockaddr_t *addr1,
00681                                     const apr_sockaddr_t *addr2);
00682 
00683 /**
00684 * Return the type of the socket.
00685 * @param sock The socket to query.
00686 * @param type The returned type (e.g., SOCK_STREAM).
00687 */
00688 APR_DECLARE(apr_status_t) apr_socket_type_get(apr_socket_t *sock,
00689                                               int *type);
00690  
00691 /**
00692  * Given an apr_sockaddr_t and a service name, set the port for the service
00693  * @param sockaddr The apr_sockaddr_t that will have its port set
00694  * @param servname The name of the service you wish to use
00695  */
00696 APR_DECLARE(apr_status_t) apr_getservbyname(apr_sockaddr_t *sockaddr, 
00697                                             const char *servname);
00698 /**
00699  * Build an ip-subnet representation from an IP address and optional netmask or
00700  * number-of-bits.
00701  * @param ipsub The new ip-subnet representation
00702  * @param ipstr The input IP address string
00703  * @param mask_or_numbits The input netmask or number-of-bits string, or NULL
00704  * @param p The pool to allocate from
00705  */
00706 APR_DECLARE(apr_status_t) apr_ipsubnet_create(apr_ipsubnet_t **ipsub, 
00707                                               const char *ipstr, 
00708                                               const char *mask_or_numbits, 
00709                                               apr_pool_t *p);
00710 
00711 /**
00712  * Test the IP address in an apr_sockaddr_t against a pre-built ip-subnet
00713  * representation.
00714  * @param ipsub The ip-subnet representation
00715  * @param sa The socket address to test
00716  * @return non-zero if the socket address is within the subnet, 0 otherwise
00717  */
00718 APR_DECLARE(int) apr_ipsubnet_test(apr_ipsubnet_t *ipsub, apr_sockaddr_t *sa);
00719 
00720 #if APR_HAS_SO_ACCEPTFILTER || defined(DOXYGEN)
00721 /**
00722  * Set an OS level accept filter.
00723  * @param sock The socket to put the accept filter on.
00724  * @param name The accept filter
00725  * @param args Any extra args to the accept filter.  Passing NULL here removes
00726  *             the accept filter. 
00727  */
00728 apr_status_t apr_socket_accept_filter(apr_socket_t *sock, char *name,
00729                                       char *args);
00730 #endif
00731 
00732 /**
00733  * Return the protocol of the socket.
00734  * @param sock The socket to query.
00735  * @param protocol The returned protocol (e.g., APR_PROTO_TCP).
00736  */
00737 APR_DECLARE(apr_status_t) apr_socket_protocol_get(apr_socket_t *sock,
00738                                                   int *protocol);
00739 
00740 /**
00741  * Set a socket to be inherited by child processes.
00742  */
00743 APR_DECLARE_INHERIT_SET(socket);
00744 
00745 /**
00746  * Unset a socket from being inherited by child processes.
00747  */
00748 APR_DECLARE_INHERIT_UNSET(socket);
00749 
00750 /**
00751  * @defgroup apr_mcast IP Multicast
00752  * @{
00753  */
00754 
00755 /**
00756  * Join a Multicast Group
00757  * @param sock The socket to join a multicast group
00758  * @param join The address of the multicast group to join
00759  * @param iface Address of the interface to use.  If NULL is passed, the 
00760  *              default multicast interface will be used. (OS Dependent)
00761  * @param source Source Address to accept transmissions from (non-NULL 
00762  *               implies Source-Specific Multicast)
00763  */
00764 APR_DECLARE(apr_status_t) apr_mcast_join(apr_socket_t *sock,
00765                                          apr_sockaddr_t *join,
00766                                          apr_sockaddr_t *iface,
00767                                          apr_sockaddr_t *source);
00768 
00769 /**
00770  * Leave a Multicast Group.  All arguments must be the same as
00771  * apr_mcast_join.
00772  * @param sock The socket to leave a multicast group
00773  * @param addr The address of the multicast group to leave
00774  * @param iface Address of the interface to use.  If NULL is passed, the 
00775  *              default multicast interface will be used. (OS Dependent)
00776  * @param source Source Address to accept transmissions from (non-NULL 
00777  *               implies Source-Specific Multicast)
00778  */
00779 APR_DECLARE(apr_status_t) apr_mcast_leave(apr_socket_t *sock,
00780                                           apr_sockaddr_t *addr,
00781                                           apr_sockaddr_t *iface,
00782                                           apr_sockaddr_t *source);
00783 
00784 /**
00785  * Set the Multicast Time to Live (ttl) for a multicast transmission.
00786  * @param sock The socket to set the multicast ttl
00787  * @param ttl Time to live to Assign. 0-255, default=1
00788  * @remark If the TTL is 0, packets will only be seen by sockets on 
00789  * the local machine, and only when multicast loopback is enabled.
00790  */
00791 APR_DECLARE(apr_status_t) apr_mcast_hops(apr_socket_t *sock,
00792                                          apr_byte_t ttl);
00793 
00794 /**
00795  * Toggle IP Multicast Loopback
00796  * @param sock The socket to set multicast loopback
00797  * @param opt 0=disable, 1=enable
00798  */
00799 APR_DECLARE(apr_status_t) apr_mcast_loopback(apr_socket_t *sock,
00800                                              apr_byte_t opt);
00801 
00802 
00803 /**
00804  * Set the Interface to be used for outgoing Multicast Transmissions.
00805  * @param sock The socket to set the multicast interface on
00806  * @param iface Address of the interface to use for Multicast
00807  */
00808 APR_DECLARE(apr_status_t) apr_mcast_interface(apr_socket_t *sock,
00809                                               apr_sockaddr_t *iface);
00810 
00811 /** @} */
00812 
00813 /** @} */
00814 
00815 #ifdef __cplusplus
00816 }
00817 #endif
00818 
00819 #endif  /* ! APR_NETWORK_IO_H */
00820 

Generated on Tue May 10 04:16:53 2005 for Apache Portable Runtime by  doxygen 1.3.9.1