📄 apr_network_io.h
字号:
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
* applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef APR_NETWORK_IO_H
#define APR_NETWORK_IO_H
/**
* @file apr_network_io.h
* @brief APR Network library
*/
#include "apr.h"
#include "apr_pools.h"
#include "apr_file_io.h"
#include "apr_errno.h"
#include "apr_inherit.h"
#if APR_HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/**
* @defgroup apr_network_io Network Routines
* @ingroup APR
* @{
*/
#ifndef APR_MAX_SECS_TO_LINGER
/** Maximum seconds to linger */
#define APR_MAX_SECS_TO_LINGER 30
#endif
#ifndef MAX_SECS_TO_LINGER
/** @deprecated @see APR_MAX_SECS_TO_LINGER */
#define MAX_SECS_TO_LINGER APR_MAX_SECS_TO_LINGER
#endif
#ifndef APRMAXHOSTLEN
/** Maximum hostname length */
#define APRMAXHOSTLEN 256
#endif
#ifndef APR_ANYADDR
/** Default 'any' address */
#define APR_ANYADDR "0.0.0.0"
#endif
/**
* @defgroup apr_sockopt Socket option definitions
* @{
*/
#define APR_SO_LINGER 1 /**< Linger */
#define APR_SO_KEEPALIVE 2 /**< Keepalive */
#define APR_SO_DEBUG 4 /**< Debug */
#define APR_SO_NONBLOCK 8 /**< Non-blocking IO */
#define APR_SO_REUSEADDR 16 /**< Reuse addresses */
#define APR_SO_TIMEOUT 32 /**< Timeout */
#define APR_SO_SNDBUF 64 /**< Send buffer */
#define APR_SO_RCVBUF 128 /**< Receive buffer */
#define APR_SO_DISCONNECTED 256 /**< Disconnected */
#define APR_TCP_NODELAY 512 /**< For SCTP sockets, this is mapped
* to STCP_NODELAY internally.
*/
#define APR_TCP_NOPUSH 1024 /**< No push */
#define APR_RESET_NODELAY 2048 /**< This flag is ONLY set internally
* when we set APR_TCP_NOPUSH with
* APR_TCP_NODELAY set to tell us that
* APR_TCP_NODELAY should be turned on
* again when NOPUSH is turned off
*/
#define APR_INCOMPLETE_READ 4096 /**< Set on non-blocking sockets
* (timeout != 0) on which the
* previous read() did not fill a buffer
* completely. the next apr_socket_recv()
* will first call select()/poll() rather than
* going straight into read(). (Can also
* be set by an application to force a
* select()/poll() call before the next
* read, in cases where the app expects
* that an immediate read would fail.)
*/
#define APR_INCOMPLETE_WRITE 8192 /**< like APR_INCOMPLETE_READ, but for write
* @see APR_INCOMPLETE_READ
*/
#define APR_IPV6_V6ONLY 16384 /**< Don't accept IPv4 connections on an
* IPv6 listening socket.
*/
/** @} */
/** Define what type of socket shutdown should occur. */
typedef enum {
APR_SHUTDOWN_READ, /**< no longer allow read request */
APR_SHUTDOWN_WRITE, /**< no longer allow write requests */
APR_SHUTDOWN_READWRITE /**< no longer allow read or write requests */
} apr_shutdown_how_e;
#define APR_IPV4_ADDR_OK 0x01 /**< @see apr_sockaddr_info_get() */
#define APR_IPV6_ADDR_OK 0x02 /**< @see apr_sockaddr_info_get() */
#if (!APR_HAVE_IN_ADDR)
/**
* We need to make sure we always have an in_addr type, so APR will just
* define it ourselves, if the platform doesn't provide it.
*/
struct in_addr {
apr_uint32_t s_addr; /**< storage to hold the IP# */
};
#endif
/**
* @def APR_INET
* Not all platforms have these defined, so we'll define them here
* The default values come from FreeBSD 4.1.1
*/
#define APR_INET AF_INET
/** @def APR_UNSPEC
* Let the system decide which address family to use
*/
#ifdef AF_UNSPEC
#define APR_UNSPEC AF_UNSPEC
#else
#define APR_UNSPEC 0
#endif
#if APR_HAVE_IPV6
#define APR_INET6 AF_INET6
#endif
/**
* @defgroup IP_Proto IP Protocol Definitions for use when creating sockets
* @{
*/
#define APR_PROTO_TCP 6 /**< TCP */
#define APR_PROTO_UDP 17 /**< UDP */
#define APR_PROTO_SCTP 132 /**< SCTP */
/** @} */
/**
* Enum to tell us if we're interested in remote or local socket
*/
typedef enum {
APR_LOCAL,
APR_REMOTE
} apr_interface_e;
/**
* The specific declaration of inet_addr's ... some platforms fall back
* inet_network (this is not good, but necessary)
*/
#if APR_HAVE_INET_ADDR
#define apr_inet_addr inet_addr
#elif APR_HAVE_INET_NETWORK /* only DGUX, as far as I know */
/**
* @warning
* not generally safe... inet_network() and inet_addr() perform
* different functions */
#define apr_inet_addr inet_network
#endif
/** A structure to represent sockets */
typedef struct apr_socket_t apr_socket_t;
/**
* A structure to encapsulate headers and trailers for apr_socket_sendfile
*/
typedef struct apr_hdtr_t apr_hdtr_t;
/** A structure to represent in_addr */
typedef struct in_addr apr_in_addr_t;
/** A structure to represent an IP subnet */
typedef struct apr_ipsubnet_t apr_ipsubnet_t;
/** @remark use apr_uint16_t just in case some system has a short that isn't 16 bits... */
typedef apr_uint16_t apr_port_t;
/** @remark It's defined here as I think it should all be platform safe...
* @see apr_sockaddr_t
*/
typedef struct apr_sockaddr_t apr_sockaddr_t;
/**
* APRs socket address type, used to ensure protocol independence
*/
struct apr_sockaddr_t {
/** The pool to use... */
apr_pool_t *pool;
/** The hostname */
char *hostname;
/** Either a string of the port number or the service name for the port */
char *servname;
/** The numeric port */
apr_port_t port;
/** The family */
apr_int32_t family;
/** Union of either IPv4 or IPv6 sockaddr. */
union {
/** IPv4 sockaddr structure */
struct sockaddr_in sin;
#if APR_HAVE_IPV6
/** IPv6 sockaddr structure */
struct sockaddr_in6 sin6;
#endif
} sa;
/** How big is the sockaddr we're using? */
apr_socklen_t salen;
/** How big is the ip address structure we're using? */
int ipaddr_len;
/** How big should the address buffer be? 16 for v4 or 46 for v6
* used in inet_ntop... */
int addr_str_len;
/** This points to the IP address structure within the appropriate
* sockaddr structure. */
void *ipaddr_ptr;
/** If multiple addresses were found by apr_sockaddr_info_get(), this
* points to a representation of the next address. */
apr_sockaddr_t *next;
};
#if APR_HAS_SENDFILE
/**
* Support reusing the socket on platforms which support it (from disconnect,
* specifically Win32.
* @remark Optional flag passed into apr_socket_sendfile()
*/
#define APR_SENDFILE_DISCONNECT_SOCKET 1
#endif
/** A structure to encapsulate headers and trailers for apr_socket_sendfile */
struct apr_hdtr_t {
/** An iovec to store the headers sent before the file. */
struct iovec* headers;
/** number of headers in the iovec */
int numheaders;
/** An iovec to store the trailers sent after the file. */
struct iovec* trailers;
/** number of trailers in the iovec */
int numtrailers;
};
/* function definitions */
/**
* Create a socket.
* @remark With APR 1.0, this function follows the prototype
* of apr_socket_create_ex.
* @param new_sock The new socket that has been set up.
* @param family The address family of the socket (e.g., APR_INET).
* @param type The type of the socket (e.g., SOCK_STREAM).
* @param cont The pool to use
*/
APR_DECLARE(apr_status_t) apr_socket_create(apr_socket_t **new_sock,
int family, int type,
apr_pool_t *cont);
/**
* Create a socket.
* @remark With APR 1.0, this function is deprecated and apr_socket_create
* follows this prototype.
* @param new_sock The new socket that has been set up.
* @param family The address family of the socket (e.g., APR_INET).
* @param type The type of the socket (e.g., SOCK_STREAM).
* @param protocol The protocol of the socket (e.g., APR_PROTO_TCP).
* @param cont The pool to use
*/
APR_DECLARE(apr_status_t) apr_socket_create_ex(apr_socket_t **new_sock,
int family, int type,
int protocol,
apr_pool_t *cont);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -