1ACCEPT(2)                     System Calls Manual                    ACCEPT(2)
2
3
4

NAME

6       accept - accept a connection on a socket
7

SYNOPSIS

9       #include <sys/types.h>
10       #include <sys/socket.h>
11
12       ns = accept(s, addr, addrlen)
13       int ns, s;
14       struct sockaddr *addr;
15       int *addrlen;
16

DESCRIPTION

18       The  argument s is a socket that has been created with socket(2), bound
19       to an address with bind(2), and is listening for  connections  after  a
20       listen(2).   Accept extracts the first connection on the queue of pend‐
21       ing connections, creates a new socket with the same properties of s and
22       allocates  a  new  file  descriptor, ns, for the socket.  If no pending
23       connections are present on the queue, and the socket is not  marked  as
24       non-blocking,  accept  blocks the caller until a connection is present.
25       If the socket is marked non-blocking and  no  pending  connections  are
26       present  on the queue, accept returns an error as described below.  The
27       accepted socket, ns, may not be used to accept more  connections.   The
28       original socket s remains open.
29
30       The  argument  addr  is  a  result parameter that is filled in with the
31       address of the connecting entity, as known to the communications layer.
32       The  exact  format of the addr parameter is determined by the domain in
33       which the communication is occurring.  The addrlen  is  a  value-result
34       parameter;  it  should initially contain the amount of space pointed to
35       by addr; on return it will contain the actual length (in bytes) of  the
36       address  returned.   This  call  is  used  with connection-based socket
37       types, currently with SOCK_STREAM.
38
39       It is possible to select(2) a socket  for  the  purposes  of  doing  an
40       accept by selecting it for read.
41

RETURN VALUE

43       The  call  returns -1 on error.  If it succeeds, it returns a non-nega‐
44       tive integer that is a descriptor for the accepted socket.
45

ERRORS

47       The accept will fail if:
48
49       [EBADF]             The descriptor is invalid.
50
51       [ENOTSOCK]          The descriptor references a file, not a socket.
52
53       [EOPNOTSUPP]        The referenced socket is not of type SOCK_STREAM.
54
55       [EFAULT]            The addr parameter is not in a writable part of the
56                           user address space.
57
58       [EWOULDBLOCK]       The  socket  is  marked non-blocking and no connec‐
59                           tions are present to be accepted.
60

SEE ALSO

62       bind(2), connect(2), listen(2), select(2), socket(2)
63
64
65
664.2 Berkeley Distribution        May 22, 1986                        ACCEPT(2)
Impressum