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
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  successful
31              call to listen().
32
33       address
34              Either  a  null  pointer,  or  a pointer to a sockaddr structure
35              where the address of the connecting socket shall be returned.
36
37       address_len
38              Points to a socklen_t structure which  on  input  specifies  the
39              length  of the supplied sockaddr structure, and on output speci‐
40              fies the length of the stored address.
41
42
43       If address is not a null pointer, the  address  of  the  peer  for  the
44       accepted  connection  shall be stored in the sockaddr structure pointed
45       to by address, and the length of this address shall be  stored  in  the
46       object pointed to by address_len.
47
48       If  the  actual length of the address is greater than the length of the
49       supplied sockaddr structure, the stored address shall be truncated.
50
51       If the protocol permits connections by unbound clients, and the peer is
52       not bound, then the value stored in the object pointed to by address is
53       unspecified.
54
55       If the listen queue is empty of connection requests and  O_NONBLOCK  is
56       not  set  on  the  file descriptor for the socket, accept() shall block
57       until a connection is present. If the listen() queue is empty  of  con‐
58       nection  requests  and O_NONBLOCK is set on the file descriptor for the
59       socket, accept() shall fail and set errno to [EAGAIN] or [EWOULDBLOCK].
60
61       The accepted socket cannot itself accept more connections. The original
62       socket remains open and can accept more connections.
63

RETURN VALUE

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

ERRORS

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

EXAMPLES

117       None.
118

APPLICATION USAGE

120       When a connection  is  available,  select()  indicates  that  the  file
121       descriptor for the socket is ready for reading.
122

RATIONALE

124       None.
125

FUTURE DIRECTIONS

127       None.
128

SEE ALSO

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