1 .\" $NetBSD: accept.2,v 1.31 2013/08/02 20:13:09 wiz Exp $
3 .\" Copyright (c) 1983, 1990, 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)accept.2 8.2 (Berkeley) 12/11/93
38 .Nd accept a connection on a socket
44 .Fn accept "int s" "struct sockaddr * restrict addr" "socklen_t * restrict addrlen"
46 .Fn paccept "int s" "struct sockaddr * restrict addr" "socklen_t * restrict addrlen" "const sigset_t * restrict sigmask" "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
59 extracts the first connection request on the queue of pending
60 connections, creates a new socket with the same properties of
62 and allocates a new file descriptor
64 If no pending connections are
65 present on the queue, and the socket is not marked
68 blocks the caller until a connection is present.
69 If the socket is marked non-blocking and no pending
70 connections are present on the queue,
72 returns an error as described below.
75 to accept more connections.
82 is a result parameter that is filled in with
83 the address of the connecting entity,
84 as known to the communications layer.
85 The exact format of the
87 parameter is determined by the domain in which the communication
91 is a value-result parameter; it should initially contain the
92 amount of space pointed to by
94 on return it will contain the actual length (in bytes) of the
97 is used with connection-based socket types, currently with
104 a socket for the purposes of doing an
106 by selecting or polling it for read.
108 For certain protocols which require an explicit confirmation,
115 as merely dequeuing the next connection
116 request and not implying confirmation.
117 Confirmation can be implied by a normal read or write on the new
118 file descriptor, and rejection can be implied by closing the
121 One can obtain user connection request data without confirming
122 the connection by issuing a
131 Similarly, one can provide user connection rejection information
134 call with providing only the control information,
140 function behaves exactly like
142 but it also allows to set the following
144 on the returned file descriptor:
145 .Bl -tag -width SOCK_NOSIGPIPEXX -offset indent
147 Set the close on exec property.
149 Sets non-blocking I/O.
150 .It Dv SOCK_NOSIGPIPE
157 It can also temporarily replace the signal mask of the calling thread if
163 function shall replace the signal mask of the caller by the set of
164 signals pointed to by
166 before waiting for a connection, and shall restore the signal mask
167 of the calling thread before returning.
173 calls return \-1 on error.
174 If they succeed, they return a non-negative
175 integer that is a descriptor for the accepted socket.
179 implementation makes the new file descriptor inherit file flags
182 from the listening socket.
183 It's a traditional behaviour for BSD derivative systems.
184 On the other hand, there are implementations which don't do so.
185 Linux is an example of such implementations.
186 Portable programs should not rely on either of the behaviours.
193 The socket is marked non-blocking and no connections
194 are present to be accepted.
196 The descriptor is invalid.
197 .It Bq Er ECONNABORTED
198 A connection has been aborted.
202 parameter is not in a writable part of the
207 call has been interrupted by a signal.
209 The socket has not been set up to accept connections (using
214 The per-process descriptor table is full.
216 The system file table is full.
218 The descriptor references a file, not a socket.
220 The referenced socket is not of type
237 function is inspired from Linux and appeared in