.\" Copyright (c) 1983, 1990, 1991 The Regents of the University of California.
.\" %sccs.include.redist.roff%
.\" @(#)accept.2 6.6 (Berkeley) %G%
.Nd accept a connection on a socket
.Fd #include <sys/types.h>
.Fd #include <sys/socket.h>
.Fn accept "int s" "struct sockaddr *addr" "int *addrlen"
is a socket that has been created with
and is listening for connections after a
extracts the first connection request
on the queue of pending connections, creates
a new socket with the same properties of
and allocates a new file descriptor
for the socket. If no pending connections are
present on the queue, and the socket is not marked
blocks the caller until a connection is present.
If the socket is marked non-blocking and no pending
connections are present on the queue,
returns an error as described below.
to accept more connections. The original socket
is a result parameter that is filled in with
the address of the connecting entity,
as known to the communications layer.
parameter is determined by the domain in which the communication
is a value-result parameter; it should initially contain the
amount of space pointed to by
on return it will contain the actual length (in bytes) of the
is used with connection-based socket types, currently with
a socket for the purposes of doing an
by selecting it for read.
For certain protocols which require an explicit confirmation,
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
One can obtain user connection request data without confirming
the connection by issuing a
Similarly, one can provide user connection rejection information
call with providing only the control information,
The call returns \-1 on error. If it succeeds, it returns a non-negative
integer that is a descriptor for the accepted socket.
.Bl -tag -width EWOULDBLOCK
The descriptor is invalid.
The descriptor references a file, not a socket.
The referenced socket is not of type
parameter is not in a writable part of the
The socket is marked non-blocking and no connections
are present to be accepted.