⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2.3.t

📁 早期freebsd实现
💻 T
📖 第 1 页 / 共 2 页
字号:
Sending and receiving data.PPMessages may be sent from a socket by:.DScc = sendto(s, buf, len, flags, to, tolen);result int cc; int s; caddr_t buf; int len, flags; caddr_t to; int tolen;.DEif the socket is not connected or:.DScc = send(s, buf, len, flags);result int cc; int s; caddr_t buf; int len, flags;.DEif the socket is connected.The corresponding receive primitives are:.DSmsglen = recvfrom(s, buf, len, flags, from, fromlenaddr);result int msglen; int s; result caddr_t buf; int len, flags;result caddr_t from; result int *fromlenaddr;.DEand.DSmsglen = recv(s, buf, len, flags);result int msglen; int s; result caddr_t buf; int len, flags;.DE.PPIn the unconnected case,the parameters \fIto\fP and \fItolen\fPspecify the destination or source of the message, whilethe \fIfrom\fP parameter stores the source of the message,and \fI*fromlenaddr\fP initially gives the size of the \fIfrom\fPbuffer and is updated to reflect the true length of the \fIfrom\fPaddress..PPAll calls cause the message to be received in or sent fromthe message buffer of length \fIlen\fP bytes, starting at address \fIbuf\fP.The \fIflags\fP specifypeeking at a message without reading it or sending or receivinghigh-priority out-of-band messages, as follows:.DS._d#define	MSG_PEEK	0x1	/* peek at incoming message */#define	MSG_OOB	0x2	/* process out-of-band data */.DE.NH 4Scatter/gather and exchanging access rights.PPIt is possible scatter and gather data and to exchange access rightswith messages.  When either of these operations is involved,the number of parameters to the call becomes large.Thus the system defines a message header structure, in \fI<sys/socket.h>\fP,which can beused to conveniently contain the parameters to the calls:.DS.if t .ta .5i 1.25i 2i 2.7i.if n ._fstruct msghdr {	caddr_t	msg_name;		/* optional address */	int	msg_namelen;	/* size of address */	struct	iov *msg_iov;	/* scatter/gather array */	int	msg_iovlen;		/* # elements in msg_iov */	caddr_t	msg_accrights;	/* access rights sent/received */	int	msg_accrightslen;	/* size of msg_accrights */};.DEHere \fImsg_name\fP and \fImsg_namelen\fP specify the source or destinationaddress if the socket is unconnected; \fImsg_name\fP may be given asa null pointer if no names are desired or required.The \fImsg_iov\fP and \fImsg_iovlen\fP describe the scatter/gatherlocations, as described in section 2.1.3.Access rights to be sent along with the message are specifiedin \fImsg_accrights\fP, which has length \fImsg_accrightslen\fP.In the ``unix'' domain these are an array of integer descriptors,taken from the sending process and duplicated in the receiver..PPThis structure is used in the operations \fIsendmsg\fP and \fIrecvmsg\fP:.DSsendmsg(s, msg, flags);int s; struct msghdr *msg; int flags;msglen = recvmsg(s, msg, flags);result int msglen; int s; result struct msghdr *msg; int flags;.DE.NH 4Using read and write with sockets.PPThe normal UNIX \fIread\fP and \fIwrite\fP calls may beapplied to connected sockets and translated into \fIsend\fP and \fIreceive\fPcalls from or to a single area of memory and discarding any rightsreceived.  A process may operate on a virtual circuit socket, a terminalor a file with blocking or non-blocking input/outputoperations without distinguishing the descriptor type..NH 4Shutting down halves of full-duplex connections.PPA process that has a full-duplex socket such as a virtual circuitand no longer wishes to read from or write to this socket cangive the call:.DSshutdown(s, direction);int s, direction;.DEwhere \fIdirection\fP is 0 to not read further, 1 to notwrite further, or 2 to completely shut the connection down.If the underlying protocol supports unidirectional or bidirectional shutdown,this indication will be passed to the peer.For example, a shutdown for writing might produce an end-of-filecondition at the remote end..NH 4Socket and protocol options.PPSockets, and their underlying communication protocols, maysupport \fIoptions\fP.  These options may be used to manipulateimplementation- or protocol-specific facilities. The \fIgetsockopt\fPand \fIsetsockopt\fP calls are used to control options:.DSgetsockopt(s, level, optname, optval, optlen)int s, level, optname; result caddr_t optval; result int *optlen;setsockopt(s, level, optname, optval, optlen)int s, level, optname; caddr_t optval; int optlen;.DEThe option \fIoptname\fP is interpreted at the indicatedprotocol \fIlevel\fP for socket \fIs\fP.  If a value is specifiedwith \fIoptval\fP and \fIoptlen\fP, it is interpreted bythe software operating at the specified \fIlevel\fP.  The \fIlevel\fPSOL_SOCKET is reserved to indicate options maintainedby the socket facilities.  Other \fIlevel\fP values indicatea particular protocol which is to act on the option request;these values are normally interpreted as a ``protocol number''..NH 3UNIX domain.PPThis section describes briefly the properties of the UNIX communicationsdomain..NH 4Types of sockets.PPIn the UNIX domain,the SOCK_STREAM abstraction provides pipe-likefacilities, while SOCK_DGRAM provides (usually)reliable message-style communications..NH 4Naming.PPSocket names are strings and may appear in the UNIX filesystem name space through portals\(dg..FS\(dg The 4.3BSD implementation of the UNIX domain embedsbound sockets in the UNIX file system name space;this may change in future releases..FE.NH 4Access rights transmission.PPThe ability to pass UNIX descriptors with messages in this domainallows migration of service within the system and allowsuser processes to be used in building system facilities..NH 3INTERNET domain.PPThis section describes briefly how the Internet domain ismapped to the model described in this section.  Moreinformation will be found in the document describing thenetwork implementation in 4.3BSD..NH 4Socket types and protocols.PPSOCK_STREAM is supported by the Internet TCP protocol;SOCK_DGRAM by the UDP protocol.Each is layered atop the transport-level Internet Protocol (IP).The Internet Control Message Protocol is implemented atop/beside IPand is accessible via a raw socket.The SOCK_SEQPACKEThas no direct Internet family analogue; a protocolbased on one from the XEROX NS family and layered ontop of IP could be implemented to fill this gap..NH 4Socket naming.PPSockets in the Internet domain have names composed of the 32 bitInternet address, and a 16 bit port number.Options may be used toprovide IP source routing or security options.The 32-bit address is composed of network and host parts;the network part is variable in size and is frequency encoded.The host part may optionally be interpreted as a subnet fieldplus the host on subnet; this is is enabled by setting a network addressmask at boot time..NH 4Access rights transmission.PPNo access rights transmission facilities are provided in the Internet domain..NH 4Raw access.PPThe Internet domain allows the super-user access to the raw facilitiesof IP.These interfaces are modeled as SOCK_RAW sockets.Each raw socket is associated with one IP protocol number,and receives all traffic received for that protocol.This allows administrative and debuggingfunctions to occur,and enables user-level implementations of special-purpose protocolssuch as inter-gateway routing protocols.

⌨️ 快捷键说明

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