2 .\" Copyright 1989 AT&T
3 .\" Copyright (C) 2002, Sun Microsystems, Inc. All Rights Reserved
4 .\" Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
5 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
6 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
7 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
8 .TH ACCEPT 3SOCKET "Apr 19, 2013"
10 accept \- accept a connection on a socket
14 \fBcc\fR [ \fIflag\fR ... ] \fIfile\fR ... \fB-lsocket\fR \fB -lnsl \fR [ \fIlibrary\fR ... ]
15 #include <sys/types.h>
16 #include <sys/socket.h>
18 \fBint\fR \fBaccept\fR(\fBint\fR \fIs\fR, \fBstruct sockaddr *\fR\fIaddr\fR, \fBsocklen_t *\fR\fIaddrlen\fR);
20 \fBint\fR \fBaccept4\fR(\fBint\fR \fIs\fR, \fBstruct sockaddr *\fR\fIaddr\fR, \fBsocklen_t *\fR\fIaddrlen\fR,
21 \fBint\fR \fIflags\fR);
26 The argument \fIs\fR is a socket that has been created with
27 \fBsocket\fR(3SOCKET) and bound to an address with \fBbind\fR(3SOCKET), and
28 that is listening for connections after a call to \fBlisten\fR(3SOCKET). The
29 \fBaccept()\fR function extracts the first connection on the queue of pending
30 connections, creates a new socket with the properties of \fIs\fR, and allocates
31 a new file descriptor, \fIns\fR, for the socket. If no pending connections are
32 present on the queue and the socket is not marked as non-blocking,
33 \fBaccept()\fR blocks the caller until a connection is present. If the socket
34 is marked as non-blocking and no pending connections are present on the queue,
35 \fBaccept()\fR returns an error as described below. The \fBaccept()\fR
36 function uses the \fBnetconfig\fR(4) file to determine the \fBSTREAMS\fR device
37 file name associated with \fIs\fR. This is the device on which the connect
38 indication will be accepted. The accepted socket, \fIns\fR, is used to read and
39 write data to and from the socket that connected to \fIns\fR. It is not used to
40 accept more connections. The original socket (\fIs\fR) remains open for
41 accepting further connections.
44 The argument \fIaddr\fR is a result parameter that is filled in with the
45 address of the connecting entity as it is known to the communications layer.
46 The exact format of the \fIaddr\fR parameter is determined by the domain in
47 which the communication occurs.
50 The argument \fIaddrlen\fR is a value-result parameter. Initially, it contains
51 the amount of space pointed to by \fIaddr\fR; on return it contains the length
52 in bytes of the address returned.
55 The \fBaccept()\fR function is used with connection-based socket types,
56 currently with \fBSOCK_STREAM\fR.
59 The \fBaccept4()\fR function allows flags that control the behavior of a
60 successfully accepted socket. If \fIflags\fR is 0, \fBaccept4()\fR acts
61 identically to \fBaccept()\fR. Values for \fIflags\fR are constructed by
62 a bitwise-inclusive-OR of flags from the following list, defined in
67 \fB\fBSOCK_CLOEXEC\fR\fR
70 The accepted socket will have the FD_CLOEXEC flag set as if \fBfcntl()\fR
71 was called on it. This flag is set before the socket is passed to the
72 caller thus avoiding the race condition between \fBaccept()\fR and
73 \fBfcntl()\fR. See, \fBO_CLOEXEC\fR in \fBopen(2)\fR for more details.
79 \fB\fBSOCK_NDELAY\fR\fR
82 The accepted socket will have the \fBO_NDELAY\fR flag set as if \fBfcntl()\fR
83 was called on it. This sets the socket into non-blocking mode. See
84 \fBO_NDELAY\fR in \fBfcntl.h(3HEAD)\fR for more details.
90 \fB\fBSOCK_NONBLOCK\fR\fR
93 The accepted socket will have the \fBO_NONBLOCK\fR flag set as if
94 \fBfcntl()\fR was called on it. This sets the socket into non-blocking mode
95 (POSIX; see \fBstandards(5)\fR). See \fBO_NONBLOCK\fR in \fBfcntl.h(3HEAD)\fR
100 It is possible to \fBselect\fR(3C) or \fBpoll\fR(2) a socket for the purpose of
101 an \fBaccept()\fR by selecting or polling it for a read. However, this will
102 only indicate when a connect indication is pending; it is still necessary to
106 The \fBaccept()\fR function returns \fB\(mi1\fR on error. If it succeeds, it
107 returns a non-negative integer that is a descriptor for the accepted socket.
110 \fBaccept()\fR and \fBaccept4()\fR will fail if:
117 The descriptor is invalid.
123 \fB\fBECONNABORTED\fR\fR
126 The remote side aborted the connection before the \fBaccept()\fR operation
136 The \fIaddr\fR parameter or the \fIaddrlen\fR parameter is invalid.
145 The \fBaccept()\fR attempt was interrupted by the delivery of a signal.
154 The per-process descriptor table is full.
163 The protocol family and type corresponding to \fIs\fR could not be found in
164 the \fBnetconfig\fR file.
173 There was insufficient user memory available to complete the operation.
182 There were insufficient \fBSTREAMS\fR resources available to complete the
192 The descriptor does not reference a socket.
198 \fB\fBEOPNOTSUPP\fR\fR
201 The referenced socket is not of type \fBSOCK_STREAM\fR.
210 A protocol error has occurred; for example, the \fBSTREAMS\fR protocol stack
211 has not been initialized or the connection has already been released.
217 \fB\fBEWOULDBLOCK\fR\fR
220 The socket is marked as non-blocking and no connections are present to be
226 \fBAdditionally, \fBaccept4()\fR will fail if:
233 The \fIflags\fR value is invalid. The \fIflags\fR argument can only be the
234 bitwise inclusive-OR of \fBSOCK_CLOEXEC\fR, \fBSOCK_NONBLOCK\fR, and
240 See \fBattributes\fR(5) for descriptions of the following attributes:
248 ATTRIBUTE TYPE ATTRIBUTE VALUE
255 \fBpoll\fR(2), \fBbind\fR(3SOCKET), \fBconnect\fR(3SOCKET),
256 \fBlisten\fR(3SOCKET), \fBsockaddr\fR(3SOCKET), \fBselect\fR(3C),
257 \fBsocket.h\fR(3HEAD), \fBsocket\fR(3SOCKET), \fBnetconfig\fR(4),
258 \fBattributes\fR(5), \fBfcntl.h(3HEAD)\fR, \fBfcntl(2)\fR, \fBstandards(5)\fR