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 .\" 3. 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
29 .\" $FreeBSD: src/lib/libc/sys/accept.2,v 1.10.2.11 2002/05/09 02:24:40 silby Exp $
30 .\" $DragonFly: src/lib/libc/sys/accept.2,v 1.4 2006/06/25 10:55:51 corecode Exp $
38 .Nd accept a connection on a socket
45 .Fn accept "int s" "struct sockaddr *addr" "socklen_t *addrlen"
47 .Fn accept4 "int s" "struct sockaddr * restrict addr" "socklen_t * restrict addrlen" "int flags"
51 is a socket that has been created with
53 bound to an address with
55 and is listening for connections after a
59 system call extracts the first connection request
60 on the queue of pending connections,
62 and allocates a new file descriptor
64 which inherits the state of the
69 socket buffer settings,
71 and the destination of
75 signals from the original socket
80 system call is similar,
83 property of the new socket is instead determined by the
91 the signal destination is cleared
92 and the close-on-exec flag on the new file descriptor can be set via the
98 If no pending connections are
99 present on the queue, and the socket is not marked
102 blocks the caller until a connection is present.
103 If the socket is marked non-blocking and no pending
104 connections are present on the queue,
106 returns an error as described below.
109 to accept more connections. The original socket
115 is a result parameter that is filled-in with
116 the address of the connecting entity,
117 as known to the communications layer.
118 The exact format of the
120 parameter is determined by the domain in which the communication
122 To ensure that the returned address fits,
124 should have a size of at least
125 .Ft sizeof(struct sockaddr_storage) .
128 is a value-result parameter; it should initially contain the
129 amount of space pointed to by
131 on return it will contain the actual length (in bytes) of the
134 are used with connection-based socket types, currently with
141 a socket for the purposes of doing an
143 by selecting it for read.
145 For certain protocols which require an explicit confirmation,
152 as merely dequeueing the next connection
153 request and not implying confirmation.
154 Confirmation can be implied by a normal read or write on the new
155 file descriptor, and rejection can be implied by closing the
158 For some applications, performance may be enhanced by using an
160 to pre-process incoming connections.
162 These calls returns \-1 on error.
164 they return a non-negative integer
165 that is a descriptor for the accepted socket.
171 system calls will fail if:
174 The descriptor is invalid.
178 operation was interrupted.
180 The per-process descriptor table is full.
182 The system file table is full.
184 The descriptor references a file, not a socket.
187 has not been called on the socket descriptor.
191 parameter is not in a writable part of the
193 .It Bq Er EWOULDBLOCK
194 The socket is marked non-blocking and no connections
195 are present to be accepted.
196 .It Bq Er ECONNABORTED
197 A connection arrived, but it was closed while waiting
203 system call will also fail if:
221 system call appeared in
226 system call appeared in