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. All advertising materials mentioning features or use of this software
13 .\" must display the following acknowledgement:
14 .\" This product includes software developed by the University of
15 .\" California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" @(#)accept.2 8.2 (Berkeley) 12/11/93
33 .\" $FreeBSD: src/lib/libc/sys/accept.2,v 1.10.2.11 2002/05/09 02:24:40 silby Exp $
34 .\" $DragonFly: src/lib/libc/sys/accept.2,v 1.4 2006/06/25 10:55:51 corecode Exp $
41 .Nd accept a connection on a socket
48 .Fn accept "int s" "struct sockaddr *addr" "socklen_t *addrlen"
52 is a socket that has been created with
54 bound to an address with
56 and is listening for connections after a
61 extracts the first connection request
62 on the queue of pending connections, creates
63 a new socket with the same properties as
65 and allocates a new file descriptor
66 for the socket. If no pending connections are
67 present on the queue, and the socket is not marked
70 blocks the caller until a connection is present.
71 If the socket is marked non-blocking and no pending
72 connections are present on the queue,
74 returns an error as described below.
77 to accept more connections. The original socket
83 is a result parameter that is filled-in with
84 the address of the connecting entity,
85 as known to the communications layer.
86 The exact format of the
88 parameter is determined by the domain in which the communication
90 To ensure that the returned address fits,
92 should have a size of at least
93 .Ft sizeof(struct sockaddr_storage) .
96 is a value-result parameter; it should initially contain the
97 amount of space pointed to by
99 on return it will contain the actual length (in bytes) of the
102 is used with connection-based socket types, currently with
107 a socket for the purposes of doing an
109 by selecting it for read.
111 For certain protocols which require an explicit confirmation,
118 as merely dequeueing the next connection
119 request and not implying confirmation.
120 Confirmation can be implied by a normal read or write on the new
121 file descriptor, and rejection can be implied by closing the
124 For some applications, performance may be enhanced by using an
126 to pre-process incoming connections.
128 The call returns \-1 on error. If it succeeds, it returns a non-negative
129 integer that is a descriptor for the accepted socket.
136 The descriptor is invalid.
140 operation was interrupted.
142 The per-process descriptor table is full.
144 The system file table is full.
146 The descriptor references a file, not a socket.
149 has not been called on the socket descriptor.
153 parameter is not in a writable part of the
155 .It Bq Er EWOULDBLOCK
156 The socket is marked non-blocking and no connections
157 are present to be accepted.
158 .It Bq Er ECONNABORTED
159 A connection arrived, but it was closed while waiting