socket.h

来自「非常好的dns解析软件」· C头文件 代码 · 共 753 行 · 第 1/2 页

H
753
字号
/* * Copyright (C) 2004-2006  Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 1998-2002  Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. *//* $Id: socket.h,v 1.57.18.6 2006/06/07 00:29:45 marka Exp $ */#ifndef ISC_SOCKET_H#define ISC_SOCKET_H 1/***** ***** Module Info *****//*! \file * \brief Provides TCP and UDP sockets for network I/O.  The sockets are event * sources in the task system. * * When I/O completes, a completion event for the socket is posted to the * event queue of the task which requested the I/O. * * \li MP: *	The module ensures appropriate synchronization of data structures it *	creates and manipulates. *	Clients of this module must not be holding a socket's task's lock when *	making a call that affects that socket.  Failure to follow this rule *	can result in deadlock. *	The caller must ensure that isc_socketmgr_destroy() is called only *	once for a given manager. * * \li Reliability: *	No anticipated impact. * * \li Resources: *	TBS * * \li Security: *	No anticipated impact. * * \li Standards: *	None. *//*** *** Imports ***/#include <isc/lang.h>#include <isc/types.h>#include <isc/event.h>#include <isc/eventclass.h>#include <isc/time.h>#include <isc/region.h>#include <isc/sockaddr.h>ISC_LANG_BEGINDECLS/*** *** Constants ***//*% * Maximum number of buffers in a scatter/gather read/write.  The operating * system in use must support at least this number (plus one on some.) */#define ISC_SOCKET_MAXSCATTERGATHER	8/*** *** Types ***/struct isc_socketevent {	ISC_EVENT_COMMON(isc_socketevent_t);	isc_result_t		result;		/*%< OK, EOF, whatever else */	unsigned int		minimum;	/*%< minimum i/o for event */	unsigned int		n;		/*%< bytes read or written */	unsigned int		offset;		/*%< offset into buffer list */	isc_region_t		region;		/*%< for single-buffer i/o */	isc_bufferlist_t	bufferlist;	/*%< list of buffers */	isc_sockaddr_t		address;	/*%< source address */	isc_time_t		timestamp;	/*%< timestamp of packet recv */	struct in6_pktinfo	pktinfo;	/*%< ipv6 pktinfo */	isc_uint32_t		attributes;	/*%< see below */	isc_eventdestructor_t   destroy;	/*%< original destructor */};typedef struct isc_socket_newconnev isc_socket_newconnev_t;struct isc_socket_newconnev {	ISC_EVENT_COMMON(isc_socket_newconnev_t);	isc_socket_t *		newsocket;	isc_result_t		result;		/*%< OK, EOF, whatever else */	isc_sockaddr_t		address;	/*%< source address */};typedef struct isc_socket_connev isc_socket_connev_t;struct isc_socket_connev {	ISC_EVENT_COMMON(isc_socket_connev_t);	isc_result_t		result;		/*%< OK, EOF, whatever else */};/*@{*//*! * _ATTACHED:	Internal use only. * _TRUNC:	Packet was truncated on receive. * _CTRUNC:	Packet control information was truncated.  This can *		indicate that the packet is not complete, even though *		all the data is valid. * _TIMESTAMP:	The timestamp member is valid. * _PKTINFO:	The pktinfo member is valid. * _MULTICAST:	The UDP packet was received via a multicast transmission. */#define ISC_SOCKEVENTATTR_ATTACHED		0x80000000U /* internal */#define ISC_SOCKEVENTATTR_TRUNC			0x00800000U /* public */#define ISC_SOCKEVENTATTR_CTRUNC		0x00400000U /* public */#define ISC_SOCKEVENTATTR_TIMESTAMP		0x00200000U /* public */#define ISC_SOCKEVENTATTR_PKTINFO		0x00100000U /* public */#define ISC_SOCKEVENTATTR_MULTICAST		0x00080000U /* public *//*@}*/#define ISC_SOCKEVENT_ANYEVENT  (0)#define ISC_SOCKEVENT_RECVDONE	(ISC_EVENTCLASS_SOCKET + 1)#define ISC_SOCKEVENT_SENDDONE	(ISC_EVENTCLASS_SOCKET + 2)#define ISC_SOCKEVENT_NEWCONN	(ISC_EVENTCLASS_SOCKET + 3)#define ISC_SOCKEVENT_CONNECT	(ISC_EVENTCLASS_SOCKET + 4)/* * Internal events. */#define ISC_SOCKEVENT_INTR	(ISC_EVENTCLASS_SOCKET + 256)#define ISC_SOCKEVENT_INTW	(ISC_EVENTCLASS_SOCKET + 257)typedef enum {	isc_sockettype_udp = 1,	isc_sockettype_tcp = 2,	isc_sockettype_unix = 3} isc_sockettype_t;/*@{*//*! * How a socket should be shutdown in isc_socket_shutdown() calls. */#define ISC_SOCKSHUT_RECV	0x00000001	/*%< close read side */#define ISC_SOCKSHUT_SEND	0x00000002	/*%< close write side */#define ISC_SOCKSHUT_ALL	0x00000003	/*%< close them all *//*@}*//*@{*//*! * What I/O events to cancel in isc_socket_cancel() calls. */#define ISC_SOCKCANCEL_RECV	0x00000001	/*%< cancel recv */#define ISC_SOCKCANCEL_SEND	0x00000002	/*%< cancel send */#define ISC_SOCKCANCEL_ACCEPT	0x00000004	/*%< cancel accept */#define ISC_SOCKCANCEL_CONNECT	0x00000008	/*%< cancel connect */#define ISC_SOCKCANCEL_ALL	0x0000000f	/*%< cancel everything *//*@}*//*@{*//*! * Flags for isc_socket_send() and isc_socket_recv() calls. */#define ISC_SOCKFLAG_IMMEDIATE	0x00000001	/*%< send event only if needed */#define ISC_SOCKFLAG_NORETRY	0x00000002	/*%< drop failed UDP sends *//*@}*//*** *** Socket and Socket Manager Functions *** *** Note: all Ensures conditions apply only if the result is success for *** those functions which return an isc_result. ***/isc_result_tisc_socket_create(isc_socketmgr_t *manager,		  int pf,		  isc_sockettype_t type,		  isc_socket_t **socketp);/*%< * Create a new 'type' socket managed by 'manager'. * * Note: * *\li	'pf' is the desired protocol family, e.g. PF_INET or PF_INET6. * * Requires: * *\li	'manager' is a valid manager * *\li	'socketp' is a valid pointer, and *socketp == NULL * * Ensures: * *	'*socketp' is attached to the newly created socket * * Returns: * *\li	#ISC_R_SUCCESS *\li	#ISC_R_NOMEMORY *\li	#ISC_R_NORESOURCES *\li	#ISC_R_UNEXPECTED */voidisc_socket_cancel(isc_socket_t *sock, isc_task_t *task,		  unsigned int how);/*%< * Cancel pending I/O of the type specified by "how". * * Note: if "task" is NULL, then the cancel applies to all tasks using the * socket. * * Requires: * * \li	"socket" is a valid socket * * \li	"task" is NULL or a valid task * * "how" is a bitmask describing the type of cancelation to perform. * The type ISC_SOCKCANCEL_ALL will cancel all pending I/O on this * socket. * * \li ISC_SOCKCANCEL_RECV: *	Cancel pending isc_socket_recv() calls. * * \li ISC_SOCKCANCEL_SEND: *	Cancel pending isc_socket_send() and isc_socket_sendto() calls. * * \li ISC_SOCKCANCEL_ACCEPT: *	Cancel pending isc_socket_accept() calls. * * \li ISC_SOCKCANCEL_CONNECT: *	Cancel pending isc_socket_connect() call. */voidisc_socket_shutdown(isc_socket_t *sock, unsigned int how);/*%< * Shutdown 'socket' according to 'how'. * * Requires: * * \li	'socket' is a valid socket. * * \li	'task' is NULL or is a valid task. * * \li	If 'how' is 'ISC_SOCKSHUT_RECV' or 'ISC_SOCKSHUT_ALL' then * *		The read queue must be empty. * *		No further read requests may be made. * * \li	If 'how' is 'ISC_SOCKSHUT_SEND' or 'ISC_SOCKSHUT_ALL' then * *		The write queue must be empty. * *		No further write requests may be made. */voidisc_socket_attach(isc_socket_t *sock, isc_socket_t **socketp);/*%< * Attach *socketp to socket. * * Requires: * * \li	'socket' is a valid socket. * * \li	'socketp' points to a NULL socket. * * Ensures: * * \li	*socketp is attached to socket. */voidisc_socket_detach(isc_socket_t **socketp);/*%< * Detach *socketp from its socket. * * Requires: * * \li	'socketp' points to a valid socket. * * \li	If '*socketp' is the last reference to the socket, *	then: * *		There must be no pending I/O requests. * * Ensures: * * \li	*socketp is NULL. * * \li	If '*socketp' is the last reference to the socket, *	then: * *		The socket will be shutdown (both reading and writing) *		for all tasks. * *		All resources used by the socket have been freed */isc_result_tisc_socket_bind(isc_socket_t *sock, isc_sockaddr_t *addressp);/*%< * Bind 'socket' to '*addressp'. * * Requires: * * \li	'socket' is a valid socket * * \li	'addressp' points to a valid isc_sockaddr. * * Returns: * * \li	ISC_R_SUCCESS * \li	ISC_R_NOPERM * \li	ISC_R_ADDRNOTAVAIL * \li	ISC_R_ADDRINUSE * \li	ISC_R_BOUND * \li	ISC_R_UNEXPECTED */isc_result_tisc_socket_filter(isc_socket_t *sock, const char *filter);/*%< * Inform the kernel that it should perform accept filtering. * If filter is NULL the current filter will be removed.:w */isc_result_tisc_socket_listen(isc_socket_t *sock, unsigned int backlog);/*%< * Set listen mode on the socket.  After this call, the only function that * can be used (other than attach and detach) is isc_socket_accept(). * * Notes: * * \li	'backlog' is as in the UNIX system call listen() and may be *	ignored by non-UNIX implementations. * * \li	If 'backlog' is zero, a reasonable system default is used, usually *	SOMAXCONN. * * Requires: * * \li	'socket' is a valid, bound TCP socket or a valid, bound UNIX socket. * * Returns: * * \li	ISC_R_SUCCESS * \li	ISC_R_UNEXPECTED */isc_result_tisc_socket_accept(isc_socket_t *sock,		  isc_task_t *task, isc_taskaction_t action, const void *arg);/*%< * Queue accept event.  When a new connection is received, the task will * get an ISC_SOCKEVENT_NEWCONN event with the sender set to the listen * socket.  The new socket structure is sent inside the isc_socket_newconnev_t * event type, and is attached to the task 'task'. * * REQUIRES: * \li	'socket' is a valid TCP socket that isc_socket_listen() was called *	on.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?