2 .\" Copyright (c) 1992, X/Open Company Limited All Rights Reserved Portions Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved
3 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
4 .\" http://www.opengroup.org/bookstore/.
5 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
6 .\" This notice shall appear on any product containing this material.
7 .\" 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.
8 .\" 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.
9 .\" 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]
10 .TH ACCEPT 3XNET "Nov 1, 2003"
12 accept \- accept a new connection on a socket
16 \fBcc\fR [ \fIflag\fR ... ] \fIfile\fR ... \fB-lxnet\fR [ \fIlibrary\fR ... ]
17 #include <sys/socket.h>
20 \fBint\fR \fBaccept\fR(\fBint\fR \fIsocket\fR, \fBstruct sockaddr *restrict\fR \fIaddress\fR,
21 \fBsocklen_t *restrict\fR \fIaddress_len\fR);
26 The \fBaccept()\fR function extracts the first connection on the queue of
27 pending connections, creates a new socket with the same socket type protocol
28 and address family as the specified socket, and allocates a new file descriptor
32 The function takes the following arguments:
39 Specifies a socket that was created with \fBsocket\fR(3XNET), has been bound to
40 an address with \fBbind\fR(3XNET), and has issued a successful call to
50 Either a null pointer, or a pointer to a \fBsockaddr\fR structure where the
51 address of the connecting socket will be returned.
57 \fB\fIaddress_len\fR\fR
60 Points to a \fBsocklen_t\fR which on input specifies the length of the supplied
61 \fBsockaddr\fR structure, and on output specifies the length of the stored
67 If \fIaddress\fR is not a null pointer, the address of the peer for the
68 accepted connection is stored in the \fBsockaddr\fR structure pointed to by
69 \fIaddress\fR, and the length of this address is stored in the object pointed
70 to by \fIaddress_len\fR.
73 If the actual length of the address is greater than the length of the supplied
74 \fBsockaddr\fR structure, the stored address will be truncated.
77 If the protocol permits connections by unbound clients, and the peer is not
78 bound, then the value stored in the object pointed to by \fIaddress\fR is
82 If the listen queue is empty of connection requests and O_NONBLOCK is not set
83 on the file descriptor for the socket, \fBaccept()\fR will block until a
84 connection is present. If the \fBlisten\fR(3XNET) queue is empty of connection
85 requests and O_NONBLOCK is set on the file descriptor for the socket,
86 \fBaccept()\fR will fail and set \fBerrno\fR to \fBEAGAIN\fR or
90 The accepted socket cannot itself accept more connections. The original socket
91 remains open and can accept more connections.
94 When a connection is available, \fBselect\fR(3C) will indicate that the file
95 descriptor for the socket is ready for reading.
98 Upon successful completion, \fBaccept()\fR returns the nonnegative file
99 descriptor of the accepted socket. Otherwise, \(mi1 is returned and
100 \fBerrno\fR is set to indicate the error.
103 The \fBaccept()\fR function will fail if:
111 \fB\fBEWOULDBLOCK\fR\fR
114 O_NONBLOCK is set for the socket file descriptor and no connections are present
124 The \fIsocket\fR argument is not a valid file descriptor.
130 \fB\fBECONNABORTED\fR\fR
133 A connection has been aborted.
142 The \fIaddress\fR or \fIaddress_len\fR parameter can not be accessed or
152 The \fBaccept()\fR function was interrupted by a signal that was caught before
153 a valid connection arrived.
162 The \fIsocket\fR is not accepting connections.
171 \fBOPEN_MAX\fR file descriptors are currently open in the calling process.
180 The maximum number of file descriptors in the system are already open.
189 The \fIsocket\fR argument does not refer to a socket.
195 \fB\fBEOPNOTSUPP\fR\fR
198 The socket type of the specified socket does not support accepting connections.
203 The \fBaccept()\fR function may fail if:
210 No buffer space is available.
219 There was insufficient memory available to complete the operation.
228 There was insufficient STREAMS resources available to complete the operation.
237 A protocol error has occurred; for example, the STREAMS protocol stack has not
243 See \fBattributes\fR(5) for descriptions of the following attributes:
251 ATTRIBUTE TYPE ATTRIBUTE VALUE
253 Interface Stability Standard
260 \fBsockaddr\fR(3SOCKET),
261 \fBbind\fR(3XNET), \fBconnect\fR(3XNET), \fBlisten\fR(3XNET),
262 \fBsocket\fR(3XNET), \fBattributes\fR(5), \fBstandards\fR(5)