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

📄 socket.2

📁 早期freebsd实现
💻 2
字号:
.\" Copyright (c) 1983, 1991, 1993.\"	The Regents of the University of California.  All rights reserved..\".\" Redistribution and use in source and binary forms, with or without.\" modification, are permitted provided that the following conditions.\" are met:.\" 1. Redistributions of source code must retain the above copyright.\"    notice, this list of conditions and the following disclaimer..\" 2. Redistributions in binary form must reproduce the above copyright.\"    notice, this list of conditions and the following disclaimer in the.\"    documentation and/or other materials provided with the distribution..\" 3. All advertising materials mentioning features or use of this software.\"    must display the following acknowledgement:.\"	This product includes software developed by the University of.\"	California, Berkeley and its contributors..\" 4. Neither the name of the University nor the names of its contributors.\"    may be used to endorse or promote products derived from this software.\"    without specific prior written permission..\".\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION).\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF.\" SUCH DAMAGE..\".\"     @(#)socket.2	8.1 (Berkeley) 6/4/93.\".Dd June 4, 1993.Dt SOCKET 2.Os BSD 4.2.Sh NAME.Nm socket.Nd create an endpoint for communication.Sh SYNOPSIS.Fd #include <sys/types.h>.Fd #include <sys/socket.h>.Ft int.Fn socket "int domain" "int type" "int protocol".Sh DESCRIPTION.Fn Socketcreates an endpoint for communication and returns a descriptor..PpThe.Fa domainparameter specifies a communications domain within whichcommunication will take place; this selects the protocol familywhich should be used.These families are defined in the include file.Ao Pa sys/socket.h Ac .The currently understood formats are.Pp.Bd -literal -offset indent -compactAF_UNIX		(UNIX internal protocols),AF_INET		(ARPA Internet protocols),AF_ISO		(ISO protocols),AF_NS		(Xerox Network Systems protocols), andAF_IMPLINK	(IMP \*(lqhost at IMP\*(rq link layer)..Ed.PpThe socket has the indicated.Fa type ,which specifies the semantics of communication.  Currentlydefined types are:.Pp.Bd -literal -offset indent -compactSOCK_STREAMSOCK_DGRAMSOCK_RAWSOCK_SEQPACKETSOCK_RDM.Ed.PpA.Dv SOCK_STREAMtype provides sequenced, reliable,two-way connection based byte streams.An out-of-band data transmission mechanism may be supported.A.Dv SOCK_DGRAMsocket supportsdatagrams (connectionless, unreliable messages ofa fixed (typically small) maximum length).A.Dv SOCK_SEQPACKETsocket may provide a sequenced, reliable,two-way connection-based data transmission path for datagramsof fixed maximum length; a consumer may be required to readan entire packet with each read system call.This facility is protocol specific, and presently implementedonly for.Dv PF_NS ..Dv SOCK_RAWsockets provide access to internal network protocols and interfaces.The types.Dv SOCK_RAW ,which is available only to the super-user, and.Dv SOCK_RDM ,which is planned,but not yet implemented, are not described here..PpThe.Fa protocolspecifies a particular protocol to be used with the socket.Normally only a single protocol exists to support a particularsocket type within a given protocol family.  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 \*(lqcommunication domain\*(rq in which communicationis to take place; see.Xr protocols 5 ..PpSockets of type.Dv SOCK_STREAMare full-duplex byte streams, similarto pipes.  A stream socket must be in a.Em connectedstate before any data may be sent or receivedon it.  A connection to another socket is created with a.Xr connect 2call.  Once connected, data may be transferred using.Xr read 2and.Xr write 2calls or some variant of the .Xr send 2and.Xr recv 2calls.  When a session has been completed a.Xr close 2may be performed.Out-of-band data may also be transmitted as described in.Xr send 2and received as described in.Xr recv 2 ..PpThe communications protocols used to implement a.Dv SOCK_STREAMinsure 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.Dv ETIMEDOUTas the specific codein the global variable.Va errno .The protocols optionally keep sockets.Dq warmby forcing transmissionsroughly every minute in the absence of other activity.An error is then indicated if no response can beelicited on an otherwiseidle connection for a extended period (e.g. 5 minutes).A.Dv SIGPIPEsignal is raised if a process sendson a broken stream; this causes naive processes,which do not handle the signal, to exit..Pp.Dv SOCK_SEQPACKETsockets employ the same system callsas.Dv SOCK_STREAMsockets.  The only differenceis that .Xr read 2calls will return only the amount of data requested,and any remaining in the arriving packet will be discarded..Pp.Dv SOCK_DGRAMand.Dv SOCK_RAWsockets allow sending of datagrams to correspondentsnamed in.Xr send 2calls.  Datagrams are generally received with.Xr recvfrom 2 ,which returns the next datagram with its return address..PpAn .Xr fcntl 2call can be used to specify a process group to receivea.Dv SIGURGsignal when the out-of-band data arrives.It may also enable non-blocking I/Oand asynchronous notification of I/O eventsvia.Dv SIGIO ..PpThe operation of sockets is controlled by socket level.Em options .These options are defined in the file.Ao Pa sys/socket.h Ac ..Xr Setsockopt 2and.Xr getsockopt 2are used to set and get options, respectively..Sh RETURN VALUESA -1 is returned if an error occurs, otherwise the returnvalue is a descriptor referencing the socket..Sh ERRORSThe.Fn socketcall fails if:.Bl -tag -width EPROTONOPSUPPORTA.It Bq Er EPROTONOSUPPORTThe protocol type or the specified protocol is not supportedwithin this domain..It Bq Er EMFILEThe per-process descriptor table is full..It Bq Er ENFILEThe system file table is full..It Bq Er EACCESSPermission to create a socket of the specified type and/or protocolis denied..It Bq Er ENOBUFSInsufficient buffer space is available.The socket cannot be created until sufficient resources are freed..El.Sh SEE ALSO.Xr accept 2 ,.Xr bind 2 ,.Xr connect 2 ,.Xr getprotoent 3 ,.Xr getsockname 2 ,.Xr getsockopt 2 ,.Xr ioctl 2 ,.Xr listen 2 ,.Xr read 2 ,.Xr recv 2 ,.Xr select 2 ,.Xr send 2 ,.Xr shutdown 2 ,.Xr socketpair 2 ,.Xr write 2.Rs.%T "An Introductory 4.3 BSD Interprocess Communication Tutorial".%O "reprinted in UNIX Programmer's Supplementary Documents Volume 1".Re.Rs.%T "BSD Interprocess Communication Tutorial".%O "reprinted in UNIX Programmer's Supplementary Documents Volume 1".Re.Sh HISTORYThe.Nmfunction call appeared in.Bx 4.2 .

⌨️ 快捷键说明

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