BSD 4_3_Net_2 release
[unix-history] / usr / src / lib / libc / sys / accept.2
index 55e2e4b..6a0feb3 100644 (file)
-.\" Copyright (c) 1983, 1990 The Regents of the University of California.
+.\" Copyright (c) 1983, 1990, 1991 The Regents of the University of California.
 .\" All rights reserved.
 .\"
 .\" All rights reserved.
 .\"
-.\" Redistribution and use in source and binary forms are permitted
-.\" provided that: (1) source distributions retain this entire copyright
-.\" notice and comment, and (2) distributions including binaries display
-.\" the following acknowledgement:  ``This product includes software
-.\" developed by the University of California, Berkeley and its contributors''
-.\" in the documentation or other materials provided with the distribution
-.\" and in all advertising materials mentioning features or use of this
-.\" software. 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR
-.\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
-.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+.\" 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.
 .\"
 .\"
-.\"    @(#)accept.2    6.5 (Berkeley) 5/30/90
+.\" 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.
 .\"
 .\"
-.TH ACCEPT 2 "May 30, 1990"
-.UC 5
-.SH NAME
-accept \- accept a connection on a socket
-.SH SYNOPSIS
-.ft B
-.nf
-#include <sys/types.h>
-#include <sys/socket.h>
-.PP
-.ft B
-ns = accept(s, addr, addrlen)
-int ns, s;
-struct sockaddr *addr;
-int *addrlen;
-.fi
-.SH DESCRIPTION
+.\"     @(#)accept.2   6.6 (Berkeley) 4/29/91
+.\"
+.Dd April 29, 1991
+.Dt ACCEPT 2
+.Os BSD 4.2
+.Sh NAME
+.Nm accept
+.Nd accept a connection on a socket
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <sys/socket.h>
+.Ft int
+.Fn accept "int s" "struct sockaddr *addr" "int *addrlen"
+.Sh DESCRIPTION
 The argument
 The argument
-.I s
+.Fa s
 is a socket that has been created with
 is a socket that has been created with
-.IR socket (2),
+.Xr socket 2 ,
 bound to an address with
 bound to an address with
-.IR bind (2),
+.Xr bind 2 ,
 and is listening for connections after a
 and is listening for connections after a
-.IR listen (2).
-.I Accept
+.Xr listen 2 .
+The
+.Fn accept
+argument
 extracts the first connection request
 on the queue of pending connections, creates
 a new socket with the same properties of 
 extracts the first connection request
 on the queue of pending connections, creates
 a new socket with the same properties of 
-.I s
-and allocates a new file descriptor,
-.IR ns ,
+.Fa s
+and allocates a new file descriptor
 for the socket.  If no pending connections are
 present on the queue, and the socket is not marked
 as non-blocking,
 for the socket.  If no pending connections are
 present on the queue, and the socket is not marked
 as non-blocking,
-.I accept
+.Fn accept
 blocks the caller until a connection is present.
 If the socket is marked non-blocking and no pending
 connections are present on the queue, 
 blocks the caller until a connection is present.
 If the socket is marked non-blocking and no pending
 connections are present on the queue, 
-.I accept
+.Fn accept
 returns an error as described below.
 returns an error as described below.
-The accepted socket,
-.IR ns ,
+The accepted socket
 may not be used
 to accept more connections.  The original socket
 may not be used
 to accept more connections.  The original socket
-.I s
+.Fa s
 remains open.
 remains open.
-.PP
+.Pp
 The argument
 The argument
-.I addr
+.Fa addr
 is a result parameter that is filled in with
 the address of the connecting entity,
 as known to the communications layer.
 The exact format of the
 is a result parameter that is filled in with
 the address of the connecting entity,
 as known to the communications layer.
 The exact format of the
-.I addr
+.Fa addr
 parameter is determined by the domain in which the communication
 is occurring.
 The 
 parameter is determined by the domain in which the communication
 is occurring.
 The 
-.I addrlen
+.Fa addrlen
 is a value-result parameter; it should initially contain the
 amount of space pointed to by
 is a value-result parameter; it should initially contain the
 amount of space pointed to by
-.IR addr ;
+.Fa addr ;
 on return it will contain the actual length (in bytes) of the
 address returned.
 This call
 on return it will contain the actual length (in bytes) of the
 address returned.
 This call
-is used with connection-based socket types, currently with SOCK_STREAM.
-.PP
+is used with connection-based socket types, currently with
+.Dv SOCK_STREAM . 
+.Pp
 It is possible to
 It is possible to
-.IR select (2)
+.Xr select 2
 a socket for the purposes of doing an
 a socket for the purposes of doing an
-.I accept
+.Fn accept
 by selecting it for read.
 by selecting it for read.
-.PP
+.Pp
 For certain protocols which require an explicit confirmation,
 For certain protocols which require an explicit confirmation,
-such as ISO or DATAKIT,
-one should think of accept as merely dequeueing the next connection
-request, and not in of itself implying confirmation.
+such as
+.Tn ISO
+or
+.Tn DATAKIT ,
+.Fn accept
+can be thought of
+as merely dequeueing the next connection
+request and not implying confirmation.
 Confirmation can be implied by a normal read or write on the new
 file desciptor, and rejection can be implied by closing the
 new socket.
 Confirmation can be implied by a normal read or write on the new
 file desciptor, and rejection can be implied by closing the
 new socket.
-.PP
+.Pp
 One can obtain user connection request data without confirming
 the connection by issuing a 
 One can obtain user connection request data without confirming
 the connection by issuing a 
-recvmsg call with an msg_iovlen of 0 and a non-zero
-msg_controllen, or by issuing a
-.IR getsockopt (2)
+.Xr recvmsg 2
+call with an
+.Fa msg_iovlen
+of 0 and a non-zero
+.Fa msg_controllen ,
+or by issuing a
+.Xr getsockopt 2
 request.
 Similarly, one can provide user connection rejection information
 request.
 Similarly, one can provide user connection rejection information
-by issuing a sendmsg call with providing only the control information,
+by issuing a
+.Xr sendmsg 2
+call with providing only the control information,
 or by calling
 or by calling
-.IR setsockopt (2).
-.SH "RETURN VALUE
+.Xr setsockopt 2 .
+.Sh RETURN VALUES
 The call returns \-1 on error.  If it succeeds, it returns a non-negative
 integer that is a descriptor for the accepted socket.
 The call returns \-1 on error.  If it succeeds, it returns a non-negative
 integer that is a descriptor for the accepted socket.
-.SH ERRORS
-The \fIaccept\fP will fail if:
-.TP 20
-[EBADF]
+.Sh ERRORS
+The
+.Fn accept
+will fail if:
+.Bl -tag -width EWOULDBLOCK
+.It Bq Er EBADF
 The descriptor is invalid.
 The descriptor is invalid.
-.TP 20
-[ENOTSOCK]
+.It Bq Er ENOTSOCK
 The descriptor references a file, not a socket.
 The descriptor references a file, not a socket.
-.TP 20
-[EOPNOTSUPP]
-The referenced socket is not of type SOCK_STREAM.
-.TP 20
-[EFAULT]
-The \fIaddr\fP parameter is not in a writable part of the
+.It Bq Er EOPNOTSUPP
+The referenced socket is not of type
+.Dv SOCK_STREAM . 
+.It Bq Er EFAULT
+The
+.Fa addr
+parameter is not in a writable part of the
 user address space.
 user address space.
-.TP 20
-[EWOULDBLOCK]
+.It Bq Er EWOULDBLOCK
 The socket is marked non-blocking and no connections
 are present to be accepted.
 The socket is marked non-blocking and no connections
 are present to be accepted.
-.SH SEE ALSO
-bind(2), connect(2), listen(2), select(2), socket(2)
+.El
+.Sh SEE ALSO
+.Xr bind 2 ,
+.Xr connect 2 ,
+.Xr listen 2 ,
+.Xr select 2 ,
+.Xr socket 2
+.Sh HISTORY
+The
+.Nm
+function appeared in 
+.Bx 4.2 .