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

📄 socket.2

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 2
字号:
.\" SCCSID: @(#)socket.2	6.1	4/27/89.TH socket 2.SH Namesocket \- create an endpoint for communication.SH Syntax.B #include <sys/types.h>.br.B #include <sys/socket.h>.PP.nf.B s = socket(af, type, protocol).B int s, af, type, protocol;.fi.SH Description.NXR "socket system call".NXR "socket" "creating".NXR "socket system call" "accept system call".NXR "socket system call" "bind system call".NXR "socket system call" "connect system call".NXR "socket system call" "getsockname system call".NXR "socket system call" "pipe system call".NXR "socket system call" "recv system call".NXR "socket system call" "socketpair system call"The.PN socketsystem callcreates an endpoint for communication and returns a descriptor..PPThe operation of sockets is controlled by socket-level options, definedin the file .PN <sys/socket.h>and explained in the section, Socket-level Options.  The calls.MS setsockopt 2and.MS getsockopt 2are used to set and get options..SH ArgumentsThe.I afparameter specifies an address format. Addresses specifiedin later operations using the socket are interpreted accordingto these formats.  Theformats are defined in the include file .PN <sys/socket.h> : .NXR "socket system call" "address formats".PP.EXAF_UNIX	\fRUNIX path names\fPAF_INET	\fRARPA Internet addresses\fPAF_IMPLINK	\fRIMP \*(lqhost at IMP\*(rq addresses\fPAF_DLI		\fRFor access to broadcast devices (Ethernet)\fP.EE.PPThe .I typeargument specifies the semantics of communication.  The defined types are:.NXR "socket" "defined types".PP.EXSOCK_STREAMSOCK_DGRAMSOCK_RAWSOCK_SEQPACKET.EE.PPThe SOCK_STREAM and SOCK_DGRAM types are available only ifyour system includes the TCP/IP network.  For example,if you can use the.PN rlogincommand to log in to a remote ULTRIX node, your systemsupports these socket types..PPA SOCK_STREAM type provides sequenced, reliable,2-way-connection-based byte streams with an out-of-band datatransmission mechanism.A SOCK_DGRAM socket supportsdatagrams (connectionless, unreliable messages ofa fixed maximum length, typically small)..NXR "datagram" "defined".PPSOCK_RAW sockets provide access to internal network interfacesand are available only to the super-user.  .PPThe SOCK_SEQPACKET type is the socket protocol to request whenyou want to communicate with other Digital systems using DECnet. .PPSocket types are discussed further in following sections..PPThe.I protocolargument specifies the protocol to be used with the socket.Normally, only a single protocol exists to support a particularsocket type using a given address format.  However, it is possiblethat many protocols may exist, in which case a particular protocolmust be specified in this manner.  The protocol number to use isparticular to the communication domain in which communicationis to take place.  For further information, see.MS services 5and.MS protocols 5 ..SH Socket Type SOCK_STREAM.NXR "SOCK_STREAM socket type" "defined".PPSockets of type SOCK_STREAMare full-duplex byte streams, similarto pipes.  A stream socket must be in a.I connectedstate before any data can be sent or receivedon it.  A connection to another socket is created with a.PN connect call.  Once connected, data can be transferred using.PN read and .PN write calls or some variant of the .PN send and .PN recv calls.  When a session has been completed, a.PN close may be performed.Out-of-band data can also be transmitted as described in.MS send 2and received as described in.MS recv 2 ..PPThe communications protocols used to implement aSOCK_STREAM ensure that datais not lost or duplicated.  If a piece of data for which thepeer protocol has buffer space cannot be successfully transmittedwithin a reasonable length of time, thenthe connection is considered broken and callswill indicate an error with\-1 returns and with ETIMEDOUT as the specific codein the global variable errno.The protocols optionally keep sockets \*(lqwarm\*(rq byforcing transmissionsroughly every minute in the absence of other activity.An error is then indicated if no response can beelicited on an otherwiseidle connection for an extended period (for example, 5 minutes).A SIGPIPE signal is raised if a process sendson a broken stream; this causes processesthat do not handle the signal to exit..SH Socket Types SOCK_DGRAM and SOCK_RAW.NXR "SOCK_DGRAM socket type".NXR "SOCK_RAW socket type".PPSOCK_DGRAM and SOCK_RAWsockets allow sending of datagrams to correspondentsnamed in.MS send 2calls.  It is also possible to receive datagrams atthese sockets with.MS recv 2 ..PPAn .MS fcntl 2call can be used to specify a process group to receivea SIGURG signal when the out-of-band data arrives..PPSOCK_DGRAM sockets are the only type of socket allowed by the DataLink Interface..SH Socket Type SOCK_SEQPACKET.NXR "SOCK_SEQPACKET socket type" "defined".PPSOCK_SEQPACKET sockets are similar to datagrams exceptthat they are guaranteed to be received in the sequencethat they are sent.  They are also guaranteed to beerror-free..SH Socket-Level Options.NXR "socket system call" "options".PPThe operation of sockets is controlled by socket-leveloptions.These options are defined in the file,.PN <sys/socket.h> .The calls .PN setsockopt and.PN getsockopt are used to set and get options..PPOptions other than SO_LINGER take an integer parameter thatshould be nonzero, if the option is to be enabled, or zero (0), ifit is to be disabled.SO_LINGER uses a ``linger'' structure parameterdefined in .PN <sys/socket.h> .  This structure specifies the desired state of the option and the lingerinterval (see the following)..PP.EXSO_DEBUG             \fRTurn on recording of debugging information\fPSO_REUSEADDR         \fRAllow local address reuse\fPSO_KEEPALIVE         \fRKeep connections alive\fPSO_DONTROUTE         \fRDo not apply routing on outgoing messages\fPSO_LINGER            \fRLinger on close if data present\fPSO_BROADCAST         \fRPermit sending of broadcast messages\fPSO_ACCEPTCONN        \fRSocket has had listen()\fPSO_USELOOPBACK       \fRBypass hardware when possible\fPSO_OOBINLINE         \fRLeave received OOB data in line\fP.EE.RE.PPSO_DEBUG enables debugging in the underlying protocol modules..PPSO_REUSEADDR indicates the rules used in validating addresses suppliedin a.PN bind call should allow reuse of local addresses.  .PPSO_KEEPALIVE enables theperiodic transmission of messages on a connected socket.  Should theconnected party fail to respond to these messages, the connection isconsidered broken and processes using the socket are notified through a SIGIO signal.  Note that in order to receive signals on a socket theprogram must first call.MS fcntl 2with a F_SETOWN request to set the process groupof the processto receive the signal, and with a F_SETFL request to set theFASYNC flag, which enables the SIGIO signal to be sent..PPSO_DONTROUTE indicates that outgoing messages shouldbypass the standard routing facilities.  Instead, messages are directedto the appropriate network interface, according to the network portionof the destination address.  .PPSO_LINGER controls the actions taken when unsent messagesare queued on the socket and a .PN close is performed.When using the .PN setsockopt to set the linger values,the option value for the SO_LINGER command is the address of a lingerstructure:.EXstruct  linger {        int     l_onoff;       /* option on/off */        int     l_linger;      /* linger time */};.EEIf the socket promises reliable delivery of data and l_onoff is nonzero,the system blocks the process on the .PN closeattempt until it is able to transmit the data or until it decides itis unable to deliver the information.  A timeout period, termed thelinger interval, is specified in l_linger in seconds.If l_onoff is set to zero (0) and a .PN closeis issued, the system processes the close in a manner that allowsthe process to continue as quickly as possible..PPSO_BROADCAST is used to enable or disable broadcasting on the socket..SH Return Values.NXR "socket system call" "return value"A \-1 is returned if an error occurs.   Otherwise, the returnvalue is a descriptor to be used in other calls to refer tothe socket..SH Diagnostics.NXR "socket system call" "diagnostics"The.PN socketcall fails if:.TP 10[EAFNOSUPPORT]The specified address family is not supported in this versionof the system..br.ne 2.TP 10[ESOCKTNOSUPPORT]The specified socket type is not supported in this address family..br.ne 3.TP 10[EPROTONOSUPPORT]The specified protocol is not supported..TP 10[EPROTOTYPE]Request for a type of socket for which there is no supportingprotocol..TP 10[EMFILE]The per-process descriptor table is full..TP 10[ENOBUFS]No buffer space is available.  The socket cannot be created..SH See Alsoaccept(2), bind(2), close(2), connect(2), fcntl(2), getsockname(2),getsockopt(2), ioctl(2), listen(2), read (2), recv(2), select(2),send(2), setsockopt(2), shutdown(2), socketpair(2), protocols(5), services(5), write(2),.br\fIGuide to Network Programming\fR,.br\fIGuide to the Data Link Interface\fR

⌨️ 快捷键说明

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