BSD 4_4 development
[unix-history] / usr / share / man / cat2 / accept.0
ACCEPT(2) BSD Programmer's Manual ACCEPT(2)
N\bNA\bAM\bME\bE
a\bac\bcc\bce\bep\bpt\bt - accept a connection on a socket
S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS
#\b#i\bin\bnc\bcl\blu\bud\bde\be <\b<s\bsy\bys\bs/\b/t\bty\byp\bpe\bes\bs.\b.h\bh>\b>
#\b#i\bin\bnc\bcl\blu\bud\bde\be <\b<s\bsy\bys\bs/\b/s\bso\boc\bck\bke\bet\bt.\b.h\bh>\b>
_\bi_\bn_\bt
a\bac\bcc\bce\bep\bpt\bt(_\bi_\bn_\bt _\bs, _\bs_\bt_\br_\bu_\bc_\bt _\bs_\bo_\bc_\bk_\ba_\bd_\bd_\br _\b*_\ba_\bd_\bd_\br, _\bi_\bn_\bt _\b*_\ba_\bd_\bd_\br_\bl_\be_\bn);
D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
The argument _\bs is a socket that has been created with socket(2), bound
to an address with bind(2), and is listening for connections after a
listen(2). The a\bac\bcc\bce\bep\bpt\bt() argument extracts the first connection request
on the queue of pending connections, creates a new socket with the same
properties of _\bs 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, a\bac\bcc\bce\bep\bpt\bt() blocks the caller until a connection is
present. If the socket is marked non-blocking and no pending connections
are present on the queue, a\bac\bcc\bce\bep\bpt\bt() returns an error as described below.
The accepted socket may not be used to accept more connections. The
original socket _\bs remains open.
The argument _\ba_\bd_\bd_\br is a result parameter that is filled in with the ad-
dress of the connecting entity, as known to the communications layer.
The exact format of the _\ba_\bd_\bd_\br parameter is determined by the domain in
which the communication is occurring. The _\ba_\bd_\bd_\br_\bl_\be_\bn is a value-result pa-
rameter; it should initially contain the amount of space pointed to by
_\ba_\bd_\bd_\br; on return it will contain the actual length (in bytes) of the ad-
dress returned. This call is used with connection-based socket types,
currently with SOCK_STREAM.
It is possible to select(2) a socket for the purposes of doing an
a\bac\bcc\bce\bep\bpt\bt() by selecting it for read.
For certain protocols which require an explicit confirmation, such as ISO
or DATAKIT, a\bac\bcc\bce\bep\bpt\bt() can be thought of as merely dequeueing the next con-
nection request and not implying confirmation. Confirmation can be im-
plied by a normal read or write on the new file desciptor, and rejection
can be implied by closing the new socket.
One can obtain user connection request data without confirming the con-
nection by issuing a recvmsg(2) call with an _\bm_\bs_\bg_\b__\bi_\bo_\bv_\bl_\be_\bn of 0 and a non-
zero _\bm_\bs_\bg_\b__\bc_\bo_\bn_\bt_\br_\bo_\bl_\bl_\be_\bn, or by issuing a getsockopt(2) request. Similarly,
one can provide user connection rejection information by issuing a
sendmsg(2) call with providing only the control information, or by call-
ing setsockopt(2).
R\bRE\bET\bTU\bUR\bRN\bN V\bVA\bAL\bLU\bUE\bES\bS
The call returns -1 on error. If it succeeds, it returns a non-negative
integer that is a descriptor for the accepted socket.
E\bER\bRR\bRO\bOR\bRS\bS
The a\bac\bcc\bce\bep\bpt\bt() will fail if:
[EBADF] The descriptor is invalid.
[ENOTSOCK] The descriptor references a file, not a socket.
[EOPNOTSUPP]
The referenced socket is not of type SOCK_STREAM.
[EFAULT] The _\ba_\bd_\bd_\br parameter is not in a writable part of the user ad-
dress space.
[EWOULDBLOCK]
The socket is marked non-blocking and no connections are
present to be accepted.
S\bSE\bEE\bE A\bAL\bLS\bSO\bO
bind(2), connect(2), listen(2), select(2), socket(2)
H\bHI\bIS\bST\bTO\bOR\bRY\bY
The a\bac\bcc\bce\bep\bpt\bt function appeared in 4.2BSD.
4.2 Berkeley Distribution June 4, 1993 2