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

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       accept — accept a new connection on a socket
14

SYNOPSIS

16       #include <sys/socket.h>
17
18       int accept(int socket, struct sockaddr *restrict address,
19           socklen_t *restrict address_len);
20

DESCRIPTION

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

RETURN VALUE

64       Upon successful completion, accept() shall return the non-negative file
65       descriptor of the accepted socket.  Otherwise, −1 shall be returned and
66       errno set to indicate the error.
67

ERRORS

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

EXAMPLES

112       None.
113

APPLICATION USAGE

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

RATIONALE

119       None.
120

FUTURE DIRECTIONS

122       None.
123

SEE ALSO

125       bind(), connect(), listen(), socket()
126
127       The Base Definitions volume of POSIX.1‐2008, <sys_socket.h>
128
130       Portions  of  this text are reprinted and reproduced in electronic form
131       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
132       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
133       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
134       cal  and  Electronics  Engineers,  Inc  and  The  Open Group.  (This is
135       POSIX.1-2008 with the 2013 Technical Corrigendum  1  applied.)  In  the
136       event of any discrepancy between this version and the original IEEE and
137       The Open Group Standard, the original IEEE and The Open Group  Standard
138       is  the  referee document. The original Standard can be obtained online
139       at http://www.unix.org/online.html .
140
141       Any typographical or formatting errors that appear  in  this  page  are
142       most likely to have been introduced during the conversion of the source
143       files to man page format. To report such errors,  see  https://www.ker
144       nel.org/doc/man-pages/reporting_bugs.html .
145
146
147
148IEEE/The Open Group                  2013                           ACCEPT(3P)
Impressum