1ACCEPT(P)                  POSIX Programmer's Manual                 ACCEPT(P)
2
3
4

NAME

6       accept - accept a new connection on a socket
7

SYNOPSIS

9       #include <sys/socket.h>
10
11       int accept(int socket, struct sockaddr *restrict address,
12              socklen_t *restrict address_len);
13
14

DESCRIPTION

16       The  accept()  function shall extract the first connection on the queue
17       of pending connections, create a new socket with the same  socket  type
18       protocol and address family as the specified socket, and allocate a new
19       file descriptor for that socket.
20
21       The accept() function takes the following arguments:
22
23       socket Specifies a socket that was  created  with  socket(),  has  been
24              bound  to  an  address  with bind(), and has issued a successful
25              call to listen().
26
27       address
28              Either a null pointer, or a  pointer  to  a  sockaddr  structure
29              where the address of the connecting socket shall be returned.
30
31       address_len
32              Points  to  a  socklen_t  structure which on input specifies the
33              length of the supplied sockaddr structure, and on output  speci‐
34              fies the length of the stored address.
35
36
37       If  address  is  not  a  null  pointer, the address of the peer for the
38       accepted connection shall be stored in the sockaddr  structure  pointed
39       to  by  address,  and the length of this address shall be stored in the
40       object pointed to by address_len.
41
42       If the actual length of the address is greater than the length  of  the
43       supplied sockaddr structure, the stored address shall be truncated.
44
45       If the protocol permits connections by unbound clients, and the peer is
46       not bound, then the value stored in the object pointed to by address is
47       unspecified.
48
49       If  the  listen queue is empty of connection requests and O_NONBLOCK is
50       not set on the file descriptor for the  socket,  accept()  shall  block
51       until  a  connection is present. If the listen() queue is empty of con‐
52       nection requests and O_NONBLOCK is set on the file descriptor  for  the
53       socket, accept() shall fail and set errno to [EAGAIN] or [EWOULDBLOCK].
54
55       The accepted socket cannot itself accept more connections. The original
56       socket remains open and can accept more connections.
57

RETURN VALUE

59       Upon successful completion, accept() shall return the non-negative file
60       descriptor  of the accepted socket. Otherwise, -1 shall be returned and
61       errno set to indicate the error.
62

ERRORS

64       The accept() function shall fail if:
65
66       EAGAIN or EWOULDBLOCK
67
68              O_NONBLOCK is set for the socket file descriptor and no  connec‐
69              tions are present to be accepted.
70
71       EBADF  The socket argument is not a valid file descriptor.
72
73       ECONNABORTED
74
75              A connection has been aborted.
76
77       EINTR  The  accept()  function  was  interrupted  by  a signal that was
78              caught before a valid connection arrived.
79
80       EINVAL The socket is not accepting connections.
81
82       EMFILE {OPEN_MAX} file descriptors are currently open  in  the  calling
83              process.
84
85       ENFILE The maximum number of file descriptors in the system are already
86              open.
87
88       ENOTSOCK
89              The socket argument does not refer to a socket.
90
91       EOPNOTSUPP
92              The socket type of the specified socket does not support accept‐
93              ing connections.
94
95
96       The accept() function may fail if:
97
98       ENOBUFS
99              No buffer space is available.
100
101       ENOMEM There  was  insufficient memory available to complete the opera‐
102              tion.
103
104       EPROTO A protocol error has occurred; for example, the STREAMS protocol
105              stack has not been initialized.
106
107
108       The following sections are informative.
109

EXAMPLES

111       None.
112

APPLICATION USAGE

114       When  a  connection  is  available,  select()  indicates  that the file
115       descriptor for the socket is ready for reading.
116

RATIONALE

118       None.
119

FUTURE DIRECTIONS

121       None.
122

SEE ALSO

124       bind() , connect() , listen() , socket() , the Base Definitions  volume
125       of IEEE Std 1003.1-2001, <sys/socket.h>
126
128       Portions  of  this text are reprinted and reproduced in electronic form
129       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
130       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
131       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
132       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
133       event of any discrepancy between this version and the original IEEE and
134       The  Open Group Standard, the original IEEE and The Open Group Standard
135       is the referee document. The original Standard can be  obtained  online
136       at http://www.opengroup.org/unix/online.html .
137
138
139
140IEEE/The Open Group                  2003                            ACCEPT(P)
Impressum