1 .\" $NetBSD: accept.2,v 1.7 1996/01/31 20:14:42 mycroft 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. All advertising materials mentioning features or use of this software
15 .\" must display the following acknowledgement:
16 .\" This product includes software developed by the University of
17 .\" California, Berkeley and its contributors.
18 .\" 4. Neither the name of the University nor the names of its contributors
19 .\" may be used to endorse or promote products derived from this software
20 .\" without specific prior written permission.
22 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .\" @(#)accept.2 8.2 (Berkeley) 12/11/93
41 .Nd accept a connection on a socket
43 .Fd #include <sys/socket.h>
47 .Fa "struct sockaddr *restrict address"
48 .Fa "socklen_t *restrict address_len"
53 is a socket that has been created with
55 bound to an address with
57 and is listening for connections after a
60 extracts the first connection request
61 on the queue of pending connections, creates
62 a new socket with the same properties of
64 and allocates a new file descriptor
65 for the socket. If no pending connections are
66 present on the queue, and the socket is not marked
69 blocks the caller until a connection is present.
70 If the socket is marked non-blocking and no pending
71 connections are present on the queue,
73 returns an error as described below.
76 to accept more connections. The original socket
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
102 a socket for the purposes of doing an
104 by selecting it for read.
106 For certain protocols which require an explicit confirmation,
113 as merely dequeuing the next connection
114 request and not implying confirmation.
115 Confirmation can be implied by a normal read or write on the new
116 file descriptor, and rejection can be implied by closing the
119 One can obtain user connection request data without confirming
120 the connection by issuing a
129 Similarly, one can provide user connection rejection information
132 call with providing only the control information,
136 The call returns \-1 on error and the global variable
138 is set to indicate the error.
139 If it succeeds, it returns a non-negative integer
140 that is a descriptor for the accepted socket.
144 system call will fail if:
149 is not a valid file descriptor.
151 .It Bq Er ECONNABORTED
159 parameter is not in a writable part of the
165 system call was terminated by a signal.
169 is unwilling to accept connections.
172 The per-process descriptor table is full.
175 The system file table is full.
178 Insufficient memory was available to complete the operation.
182 references a file type other than a socket.
188 and thus does not accept connections.
190 .It Bq Er EWOULDBLOCK
192 is marked as non-blocking and no connections are present to be accepted.
195 .Fd #include <sys/types.h>
196 .Fd #include <sys/socket.h>