1 .\" Copyright (c) 1983, 1990, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
12 .\" 4. Neither the name of the University nor the names of its contributors
13 .\" may be used to endorse or promote products derived from this software
14 .\" without specific prior written permission.
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 .\" @(#)accept.2 8.2 (Berkeley) 12/11/93
37 .Nd accept a connection on a socket
44 .Fn accept "int s" "struct sockaddr * restrict addr" "socklen_t * restrict addrlen"
46 .Fn accept4 "int s" "struct sockaddr * restrict addr" "socklen_t * restrict addrlen" "int flags"
50 is a socket that has been created with
52 bound to an address with
54 and is listening for connections after a
58 system call extracts the first connection request on the
59 queue of pending connections, creates a new socket,
60 and allocates a new file descriptor for the socket which
61 inherits the state of the
65 properties and the destination of
69 signals from the original socket
74 system call is similar,
77 property of the new socket is instead determined by the
85 the signal destination is cleared
86 and the close-on-exec flag on the new file descriptor can be set via the
92 If no pending connections are
93 present on the queue, and the original socket
94 is not marked as non-blocking,
96 blocks the caller until a connection is present.
97 If the original socket
98 is marked non-blocking and no pending
99 connections are present on the queue,
101 returns an error as described below.
104 to accept more connections.
111 is a result argument that is filled-in with
112 the address of the connecting entity,
113 as known to the communications layer.
114 The exact format of the
116 argument is determined by the domain in which the communication
118 A null pointer may be specified for
120 if the address information is not desired;
123 is not used and should also be null.
127 is a value-result argument; it should initially contain the
128 amount of space pointed to by
130 on return it will contain the actual length (in bytes) of the
133 is used with connection-based socket types, currently with
138 a socket for the purposes of doing an
140 by selecting it for read.
142 For certain protocols which require an explicit confirmation,
149 as merely dequeueing the next connection
150 request and not implying confirmation.
151 Confirmation can be implied by a normal read or write on the new
152 file descriptor, and rejection can be implied by closing the
155 For some applications, performance may be enhanced by using an
157 to pre-process incoming connections.
161 portable programs should not rely on the
165 properties and the signal destination being inherited,
166 but should set them explicitly using
169 sets these properties consistently,
170 but may not be fully portable across
174 These calls return \-1 on error.
175 If they succeed, they return a non-negative
176 integer that is a descriptor for the accepted socket.
182 system calls will fail if:
185 The descriptor is invalid.
189 operation was interrupted.
191 The per-process descriptor table is full.
193 The system file table is full.
195 The descriptor references a file, not a socket.
198 has not been called on the socket descriptor.
202 argument is not in a writable part of the
204 .It Bo Er EWOULDBLOCK Bc or Bq Er EAGAIN
205 The socket is marked non-blocking and no connections
206 are present to be accepted.
207 .It Bq Er ECONNABORTED
208 A connection arrived, but it was closed while waiting
214 system call will also fail if:
233 system call appeared in
238 system call appeared in