man-pages/man3p/accept.3p

155 lines
4.9 KiB
Plaintext

.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved
.TH "ACCEPT" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual"
.\" accept
.SH PROLOG
This manual page is part of the POSIX Programmer's Manual.
The Linux implementation of this interface may differ (consult
the corresponding Linux manual page for details of Linux behavior),
or the interface may not be implemented on Linux.
.SH NAME
accept \- accept a new connection on a socket
.SH SYNOPSIS
.LP
\fB#include <sys/socket.h>
.br
.sp
int accept(int\fP \fIsocket\fP\fB, struct sockaddr *restrict\fP \fIaddress\fP\fB,
.br
\ \ \ \ \ \ socklen_t *restrict\fP \fIaddress_len\fP\fB);
.br
\fP
.SH DESCRIPTION
.LP
The \fIaccept\fP() function shall extract the first connection on
the queue of pending connections, create a new socket with
the same socket type protocol and address family as the specified
socket, and allocate a new file descriptor for that socket.
.LP
The \fIaccept\fP() function takes the following arguments:
.TP 7
\fIsocket\fP
Specifies a socket that was created with \fIsocket\fP(), has been
bound to an address
with \fIbind\fP(), and has issued a successful call to \fIlisten\fP().
.TP 7
\fIaddress\fP
Either a null pointer, or a pointer to a \fBsockaddr\fP structure
where the address of the connecting socket shall be
returned.
.TP 7
\fIaddress_len\fP
Points to a \fBsocklen_t\fP structure which on input specifies the
length of the supplied \fBsockaddr\fP structure, and on
output specifies the length of the stored address.
.sp
.LP
If \fIaddress\fP is not a null pointer, the address of the peer for
the accepted connection shall be stored in the
\fBsockaddr\fP structure pointed to by \fIaddress\fP, and the length
of this address shall be stored in the object pointed to by
\fIaddress_len\fP.
.LP
If the actual length of the address is greater than the length of
the supplied \fBsockaddr\fP structure, the stored address
shall be truncated.
.LP
If the protocol permits connections by unbound clients, and the peer
is not bound, then the value stored in the object pointed
to by \fIaddress\fP is unspecified.
.LP
If the listen queue is empty of connection requests and O_NONBLOCK
is not set on the file descriptor for the socket,
\fIaccept\fP() shall block until a connection is present. If the \fIlisten\fP()
queue is
empty of connection requests and O_NONBLOCK is set on the file descriptor
for the socket, \fIaccept\fP() shall fail and set
\fIerrno\fP to [EAGAIN] or [EWOULDBLOCK].
.LP
The accepted socket cannot itself accept more connections. The original
socket remains open and can accept more connections.
.SH RETURN VALUE
.LP
Upon successful completion, \fIaccept\fP() shall return the non-negative
file descriptor of the accepted socket. Otherwise, -1
shall be returned and \fIerrno\fP set to indicate the error.
.SH ERRORS
.LP
The \fIaccept\fP() function shall fail if:
.TP 7
.B EAGAIN \fRor\fP EWOULDBLOCK
.sp
O_NONBLOCK is set for the socket file descriptor and no connections
are present to be accepted.
.TP 7
.B EBADF
The \fIsocket\fP argument is not a valid file descriptor.
.TP 7
.B ECONNABORTED
.sp
A connection has been aborted.
.TP 7
.B EINTR
The \fIaccept\fP() function was interrupted by a signal that was caught
before a valid connection arrived.
.TP 7
.B EINVAL
The \fIsocket\fP is not accepting connections.
.TP 7
.B EMFILE
{OPEN_MAX} file descriptors are currently open in the calling process.
.TP 7
.B ENFILE
The maximum number of file descriptors in the system are already open.
.TP 7
.B ENOTSOCK
The \fIsocket\fP argument does not refer to a socket.
.TP 7
.B EOPNOTSUPP
The socket type of the specified socket does not support accepting
connections.
.sp
.LP
The \fIaccept\fP() function may fail if:
.TP 7
.B ENOBUFS
No buffer space is available.
.TP 7
.B ENOMEM
There was insufficient memory available to complete the operation.
.TP 7
.B EPROTO
A protocol error has occurred; for example, the STREAMS protocol stack
has not been initialized.
.sp
.LP
\fIThe following sections are informative.\fP
.SH EXAMPLES
.LP
None.
.SH APPLICATION USAGE
.LP
When a connection is available, \fIselect\fP() indicates that the
file descriptor for
the socket is ready for reading.
.SH RATIONALE
.LP
None.
.SH FUTURE DIRECTIONS
.LP
None.
.SH SEE ALSO
.LP
\fIbind\fP(), \fIconnect\fP(), \fIlisten\fP(),
\fIsocket\fP(), the Base Definitions volume of IEEE\ Std\ 1003.1-2001,
\fI<sys/socket.h>\fP
.SH COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group. In the
event of any discrepancy between this version and the original IEEE and
The Open Group Standard, the original IEEE and The Open Group Standard
is the referee document. The original Standard can be obtained online at
http://www.opengroup.org/unix/online.html .