summaryrefslogtreecommitdiff
path: root/usr/src/man/man3socket/accept.3socket
blob: c6ad97671a3374b64d63c8cc3386bdadfe2252fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
'\" te
.\" Copyright 1989 AT&T  
.\" Copyright (C) 2002, Sun Microsystems, Inc. All Rights Reserved
.\" 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.
.\" 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.
.\" 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]
.TH accept 3SOCKET "24 Jan 2002" "SunOS 5.11" "Sockets Library Functions"
.SH NAME
accept \- accept a connection on a socket
.SH SYNOPSIS
.LP
.nf
\fBcc\fR [ \fIflag\fR ... ] \fIfile\fR ... \fB-lsocket\fR \fB -lnsl \fR [ \fIlibrary\fR ... ]
#include <sys/types.h>
#include <sys/socket.h>

\fBint\fR \fBaccept\fR(\fBint\fR \fIs\fR, \fBstruct sockaddr *\fR\fIaddr\fR, \fBsocklen_t *\fR\fIaddrlen\fR);
.fi

.SH DESCRIPTION
.sp
.LP
The argument \fIs\fR is a socket that has been created with
\fBsocket\fR(3SOCKET) and bound to an address with \fBbind\fR(3SOCKET), and
that is listening for connections after a call to \fBlisten\fR(3SOCKET). The
\fBaccept()\fR function extracts the first connection on the queue of pending
connections, creates a new socket with the properties of \fIs\fR, and allocates
a new file descriptor, \fIns\fR, for the socket. If no pending connections are
present on the queue and the socket is not marked as non-blocking,
\fBaccept()\fR blocks the caller until a connection is present. If the socket
is marked as non-blocking and no pending connections are present on the queue,
\fBaccept()\fR returns an error as described below.  The \fBaccept()\fR
function uses the \fBnetconfig\fR(4) file to determine the \fBSTREAMS\fR device
file name associated with \fIs\fR.  This is the device on which the connect
indication will be accepted. The accepted socket, \fIns\fR, is used to read and
write data to and from the socket that connected to \fIns\fR. It is not used to
accept more connections. The original socket (\fIs\fR) remains open for
accepting further connections.
.sp
.LP
The argument \fIaddr\fR is a result parameter that is filled in with the
address of the connecting entity as it is known to the communications layer.
The exact format of the \fIaddr\fR parameter is determined by the domain in
which the communication occurs.
.sp
.LP
The argument \fIaddrlen\fR is a value-result parameter. Initially, it contains
the amount of space pointed to by \fIaddr\fR; on return it contains the length
in bytes of the address returned.
.sp
.LP
The \fBaccept()\fR function is used with connection-based socket types,
currently with \fBSOCK_STREAM\fR.
.sp
.LP
It is possible to \fBselect\fR(3C) or \fBpoll\fR(2) a socket for the purpose of
an \fBaccept()\fR by selecting or polling it for a read. However, this will
only indicate when a connect indication is pending; it is still necessary to
call \fBaccept()\fR.
.SH RETURN VALUES
.sp
.LP
The \fBaccept()\fR function returns \fB\(mi1\fR on error. If it succeeds, it
returns a non-negative integer that is a descriptor for the accepted socket.
.SH ERRORS
.sp
.LP
\fBaccept()\fR will fail if:
.sp
.ne 2
.mk
.na
\fB\fBEBADF\fR\fR
.ad
.RS 16n
.rt  
The descriptor is invalid.
.RE

.sp
.ne 2
.mk
.na
\fB\fBECONNABORTED\fR\fR
.ad
.RS 16n
.rt  
The remote side aborted the connection before the \fBaccept()\fR operation
completed.
.RE

.sp
.ne 2
.mk
.na
\fB\fBEFAULT\fR\fR
.ad
.RS 16n
.rt  
The \fIaddr\fR parameter or the \fIaddrlen\fR parameter is invalid.
.RE

.sp
.ne 2
.mk
.na
\fB\fBEINTR\fR\fR
.ad
.RS 16n
.rt  
The \fBaccept()\fR attempt was interrupted by the delivery of a signal.
.RE

.sp
.ne 2
.mk
.na
\fB\fBEMFILE\fR\fR
.ad
.RS 16n
.rt  
The per-process descriptor table is full.
.RE

.sp
.ne 2
.mk
.na
\fB\fBENODEV\fR\fR
.ad
.RS 16n
.rt  
The protocol family and type corresponding to  \fIs\fR could not be found in
the \fBnetconfig\fR file.
.RE

.sp
.ne 2
.mk
.na
\fB\fBENOMEM\fR\fR
.ad
.RS 16n
.rt  
There was insufficient user memory available to complete the operation.
.RE

.sp
.ne 2
.mk
.na
\fB\fBENOSR\fR\fR
.ad
.RS 16n
.rt  
There were insufficient \fBSTREAMS\fR resources available to complete the
operation.
.RE

.sp
.ne 2
.mk
.na
\fB\fBENOTSOCK\fR\fR
.ad
.RS 16n
.rt  
The descriptor does not reference a socket.
.RE

.sp
.ne 2
.mk
.na
\fB\fBEOPNOTSUPP\fR\fR
.ad
.RS 16n
.rt  
The referenced socket is not of type \fBSOCK_STREAM\fR.
.RE

.sp
.ne 2
.mk
.na
\fB\fBEPROTO\fR\fR
.ad
.RS 16n
.rt  
A protocol error has occurred; for example, the \fBSTREAMS\fR protocol stack
has not been initialized or the connection has already been released.
.RE

.sp
.ne 2
.mk
.na
\fB\fBEWOULDBLOCK\fR\fR
.ad
.RS 16n
.rt  
The socket is marked as non-blocking and no connections are present to be
accepted.
.RE

.SH ATTRIBUTES
.sp
.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp

.sp
.TS
tab() box;
cw(2.75i) |cw(2.75i) 
lw(2.75i) |lw(2.75i) 
.
ATTRIBUTE TYPEATTRIBUTE VALUE
_
MT-LevelSafe
.TE

.SH SEE ALSO
.sp
.LP
\fBpoll\fR(2), \fBbind\fR(3SOCKET), \fBconnect\fR(3SOCKET),
\fBlisten\fR(3SOCKET), \fBselect\fR(3C), \fBsocket.h\fR(3HEAD),
\fBsocket\fR(3SOCKET), \fBnetconfig\fR(4), \fBattributes\fR(5)