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