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

NAME

12       accept — accept a new connection on a socket
13

SYNOPSIS

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

DESCRIPTION

21       The accept() function shall extract the first connection on  the  queue
22       of  pending  connections, create a new socket with the same socket type
23       protocol and address family as the specified socket, and allocate a new
24       file descriptor for that socket. The file descriptor shall be allocated
25       as described in Section 2.14, File Descriptor Allocation.
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,
66       errno shall be set to indicate the error, and any object pointed to  by
67       address_len shall remain unchanged.
68

ERRORS

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

EXAMPLES

113       None.
114

APPLICATION USAGE

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

RATIONALE

120       None.
121

FUTURE DIRECTIONS

123       None.
124

SEE ALSO

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