1*043036a2SApple OSS Distributions.\" $NetBSD: accept.2,v 1.7 1996/01/31 20:14:42 mycroft Exp $ 2*043036a2SApple OSS Distributions.\" 3*043036a2SApple OSS Distributions.\" Copyright (c) 1983, 1990, 1991, 1993 4*043036a2SApple OSS Distributions.\" The Regents of the University of California. All rights reserved. 5*043036a2SApple OSS Distributions.\" 6*043036a2SApple OSS Distributions.\" Redistribution and use in source and binary forms, with or without 7*043036a2SApple OSS Distributions.\" modification, are permitted provided that the following conditions 8*043036a2SApple OSS Distributions.\" are met: 9*043036a2SApple OSS Distributions.\" 1. Redistributions of source code must retain the above copyright 10*043036a2SApple OSS Distributions.\" notice, this list of conditions and the following disclaimer. 11*043036a2SApple OSS Distributions.\" 2. Redistributions in binary form must reproduce the above copyright 12*043036a2SApple OSS Distributions.\" notice, this list of conditions and the following disclaimer in the 13*043036a2SApple OSS Distributions.\" documentation and/or other materials provided with the distribution. 14*043036a2SApple OSS Distributions.\" 3. All advertising materials mentioning features or use of this software 15*043036a2SApple OSS Distributions.\" must display the following acknowledgement: 16*043036a2SApple OSS Distributions.\" This product includes software developed by the University of 17*043036a2SApple OSS Distributions.\" California, Berkeley and its contributors. 18*043036a2SApple OSS Distributions.\" 4. Neither the name of the University nor the names of its contributors 19*043036a2SApple OSS Distributions.\" may be used to endorse or promote products derived from this software 20*043036a2SApple OSS Distributions.\" without specific prior written permission. 21*043036a2SApple OSS Distributions.\" 22*043036a2SApple OSS Distributions.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23*043036a2SApple OSS Distributions.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24*043036a2SApple OSS Distributions.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25*043036a2SApple OSS Distributions.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26*043036a2SApple OSS Distributions.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27*043036a2SApple OSS Distributions.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28*043036a2SApple OSS Distributions.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29*043036a2SApple OSS Distributions.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30*043036a2SApple OSS Distributions.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31*043036a2SApple OSS Distributions.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32*043036a2SApple OSS Distributions.\" SUCH DAMAGE. 33*043036a2SApple OSS Distributions.\" 34*043036a2SApple OSS Distributions.\" @(#)accept.2 8.2 (Berkeley) 12/11/93 35*043036a2SApple OSS Distributions.\" 36*043036a2SApple OSS Distributions.Dd March 18, 2015 37*043036a2SApple OSS Distributions.Dt ACCEPT 2 38*043036a2SApple OSS Distributions.Os BSD 4.2 39*043036a2SApple OSS Distributions.Sh NAME 40*043036a2SApple OSS Distributions.Nm accept 41*043036a2SApple OSS Distributions.Nd accept a connection on a socket 42*043036a2SApple OSS Distributions.Sh SYNOPSIS 43*043036a2SApple OSS Distributions.Fd #include <sys/socket.h> 44*043036a2SApple OSS Distributions.Ft int 45*043036a2SApple OSS Distributions.Fo accept 46*043036a2SApple OSS Distributions.Fa "int socket" 47*043036a2SApple OSS Distributions.Fa "struct sockaddr *restrict address" 48*043036a2SApple OSS Distributions.Fa "socklen_t *restrict address_len" 49*043036a2SApple OSS Distributions.Fc 50*043036a2SApple OSS Distributions.Sh DESCRIPTION 51*043036a2SApple OSS DistributionsThe argument 52*043036a2SApple OSS Distributions.Fa socket 53*043036a2SApple OSS Distributionsis a socket that has been created with 54*043036a2SApple OSS Distributions.Xr socket 2 , 55*043036a2SApple OSS Distributionsbound to an address with 56*043036a2SApple OSS Distributions.Xr bind 2 , 57*043036a2SApple OSS Distributionsand is listening for connections after a 58*043036a2SApple OSS Distributions.Xr listen 2 . 59*043036a2SApple OSS Distributions.Fn accept 60*043036a2SApple OSS Distributionsextracts the first connection request 61*043036a2SApple OSS Distributionson the queue of pending connections, creates 62*043036a2SApple OSS Distributionsa new socket with the same properties of 63*043036a2SApple OSS Distributions.Fa socket , 64*043036a2SApple OSS Distributionsand allocates a new file descriptor 65*043036a2SApple OSS Distributionsfor the socket. If no pending connections are 66*043036a2SApple OSS Distributionspresent on the queue, and the socket is not marked 67*043036a2SApple OSS Distributionsas non-blocking, 68*043036a2SApple OSS Distributions.Fn accept 69*043036a2SApple OSS Distributionsblocks the caller until a connection is present. 70*043036a2SApple OSS DistributionsIf the socket is marked non-blocking and no pending 71*043036a2SApple OSS Distributionsconnections are present on the queue, 72*043036a2SApple OSS Distributions.Fn accept 73*043036a2SApple OSS Distributionsreturns an error as described below. 74*043036a2SApple OSS DistributionsThe accepted socket 75*043036a2SApple OSS Distributionsmay not be used 76*043036a2SApple OSS Distributionsto accept more connections. The original socket 77*043036a2SApple OSS Distributions.Fa socket, 78*043036a2SApple OSS Distributionsremains open. 79*043036a2SApple OSS Distributions.Pp 80*043036a2SApple OSS DistributionsThe argument 81*043036a2SApple OSS Distributions.Fa address 82*043036a2SApple OSS Distributionsis a result parameter that is filled in with 83*043036a2SApple OSS Distributionsthe address of the connecting entity, 84*043036a2SApple OSS Distributionsas known to the communications layer. 85*043036a2SApple OSS DistributionsThe exact format of the 86*043036a2SApple OSS Distributions.Fa address 87*043036a2SApple OSS Distributionsparameter is determined by the domain in which the communication 88*043036a2SApple OSS Distributionsis occurring. 89*043036a2SApple OSS DistributionsThe 90*043036a2SApple OSS Distributions.Fa address_len 91*043036a2SApple OSS Distributionsis a value-result parameter; it should initially contain the 92*043036a2SApple OSS Distributionsamount of space pointed to by 93*043036a2SApple OSS Distributions.Fa address ; 94*043036a2SApple OSS Distributionson return it will contain the actual length (in bytes) of the 95*043036a2SApple OSS Distributionsaddress returned. 96*043036a2SApple OSS DistributionsThis call 97*043036a2SApple OSS Distributionsis used with connection-based socket types, currently with 98*043036a2SApple OSS Distributions.Dv SOCK_STREAM . 99*043036a2SApple OSS Distributions.Pp 100*043036a2SApple OSS DistributionsIt is possible to 101*043036a2SApple OSS Distributions.Xr select 2 102*043036a2SApple OSS Distributionsa socket for the purposes of doing an 103*043036a2SApple OSS Distributions.Fn accept 104*043036a2SApple OSS Distributionsby selecting it for read. 105*043036a2SApple OSS Distributions.Pp 106*043036a2SApple OSS DistributionsFor certain protocols which require an explicit confirmation, 107*043036a2SApple OSS Distributionssuch as 108*043036a2SApple OSS Distributions.Tn ISO 109*043036a2SApple OSS Distributionsor 110*043036a2SApple OSS Distributions.Tn DATAKIT , 111*043036a2SApple OSS Distributions.Fn accept 112*043036a2SApple OSS Distributionscan be thought of 113*043036a2SApple OSS Distributionsas merely dequeuing the next connection 114*043036a2SApple OSS Distributionsrequest and not implying confirmation. 115*043036a2SApple OSS DistributionsConfirmation can be implied by a normal read or write on the new 116*043036a2SApple OSS Distributionsfile descriptor, and rejection can be implied by closing the 117*043036a2SApple OSS Distributionsnew socket. 118*043036a2SApple OSS Distributions.Pp 119*043036a2SApple OSS DistributionsOne can obtain user connection request data without confirming 120*043036a2SApple OSS Distributionsthe connection by issuing a 121*043036a2SApple OSS Distributions.Xr recvmsg 2 122*043036a2SApple OSS Distributionscall with an 123*043036a2SApple OSS Distributions.Fa msg_iovlen 124*043036a2SApple OSS Distributionsof 0 and a non-zero 125*043036a2SApple OSS Distributions.Fa msg_controllen , 126*043036a2SApple OSS Distributionsor by issuing a 127*043036a2SApple OSS Distributions.Xr getsockopt 2 128*043036a2SApple OSS Distributionsrequest. 129*043036a2SApple OSS DistributionsSimilarly, one can provide user connection rejection information 130*043036a2SApple OSS Distributionsby issuing a 131*043036a2SApple OSS Distributions.Xr sendmsg 2 132*043036a2SApple OSS Distributionscall with providing only the control information, 133*043036a2SApple OSS Distributionsor by calling 134*043036a2SApple OSS Distributions.Xr setsockopt 2 . 135*043036a2SApple OSS Distributions.Sh RETURN VALUES 136*043036a2SApple OSS DistributionsThe call returns \-1 on error and the global variable 137*043036a2SApple OSS Distributions.Va errno 138*043036a2SApple OSS Distributionsis set to indicate the error. 139*043036a2SApple OSS DistributionsIf it succeeds, it returns a non-negative integer 140*043036a2SApple OSS Distributionsthat is a descriptor for the accepted socket. 141*043036a2SApple OSS Distributions.Sh ERRORS 142*043036a2SApple OSS DistributionsThe 143*043036a2SApple OSS Distributions.Fn accept 144*043036a2SApple OSS Distributionssystem call will fail if: 145*043036a2SApple OSS Distributions.Bl -tag -width Er 146*043036a2SApple OSS Distributions.\" ========== 147*043036a2SApple OSS Distributions.It Bq Er EBADF 148*043036a2SApple OSS Distributions.Fa socket 149*043036a2SApple OSS Distributionsis not a valid file descriptor. 150*043036a2SApple OSS Distributions.\" ========== 151*043036a2SApple OSS Distributions.It Bq Er ECONNABORTED 152*043036a2SApple OSS DistributionsThe connection to 153*043036a2SApple OSS Distributions.Fa socket 154*043036a2SApple OSS Distributionshas been aborted. 155*043036a2SApple OSS Distributions.\" ========== 156*043036a2SApple OSS Distributions.It Bq Er EFAULT 157*043036a2SApple OSS DistributionsThe 158*043036a2SApple OSS Distributions.Fa address 159*043036a2SApple OSS Distributionsparameter is not in a writable part of the 160*043036a2SApple OSS Distributionsuser address space. 161*043036a2SApple OSS Distributions.\" ========== 162*043036a2SApple OSS Distributions.It Bq Er EINTR 163*043036a2SApple OSS DistributionsThe 164*043036a2SApple OSS Distributions.Fn accept 165*043036a2SApple OSS Distributionssystem call was terminated by a signal. 166*043036a2SApple OSS Distributions.\" ========== 167*043036a2SApple OSS Distributions.It Bq Er EINVAL 168*043036a2SApple OSS Distributions.Fa socket 169*043036a2SApple OSS Distributionsis unwilling to accept connections. 170*043036a2SApple OSS Distributions.\" ========== 171*043036a2SApple OSS Distributions.It Bq Er EMFILE 172*043036a2SApple OSS DistributionsThe per-process descriptor table is full. 173*043036a2SApple OSS Distributions.\" ========== 174*043036a2SApple OSS Distributions.It Bq Er ENFILE 175*043036a2SApple OSS DistributionsThe system file table is full. 176*043036a2SApple OSS Distributions.\" ========== 177*043036a2SApple OSS Distributions.It Bq Er ENOMEM 178*043036a2SApple OSS DistributionsInsufficient memory was available to complete the operation. 179*043036a2SApple OSS Distributions.\" ========== 180*043036a2SApple OSS Distributions.It Bq Er ENOTSOCK 181*043036a2SApple OSS Distributions.Fa socket 182*043036a2SApple OSS Distributionsreferences a file type other than a socket. 183*043036a2SApple OSS Distributions.\" ========== 184*043036a2SApple OSS Distributions.It Bq Er EOPNOTSUPP 185*043036a2SApple OSS Distributions.Fa socket 186*043036a2SApple OSS Distributionsis not of type 187*043036a2SApple OSS Distributions.Dv SOCK_STREAM 188*043036a2SApple OSS Distributionsand thus does not accept connections. 189*043036a2SApple OSS Distributions.\" ========== 190*043036a2SApple OSS Distributions.It Bq Er EWOULDBLOCK 191*043036a2SApple OSS Distributions.Fa socket 192*043036a2SApple OSS Distributionsis marked as non-blocking and no connections are present to be accepted. 193*043036a2SApple OSS Distributions.El 194*043036a2SApple OSS Distributions.Sh LEGACY SYNOPSIS 195*043036a2SApple OSS Distributions.Fd #include <sys/types.h> 196*043036a2SApple OSS Distributions.Fd #include <sys/socket.h> 197*043036a2SApple OSS Distributions.Pp 198*043036a2SApple OSS DistributionsThe include file 199*043036a2SApple OSS Distributions.In sys/types.h 200*043036a2SApple OSS Distributionsis necessary. 201*043036a2SApple OSS Distributions.Sh SEE ALSO 202*043036a2SApple OSS Distributions.Xr bind 2 , 203*043036a2SApple OSS Distributions.Xr connect 2 , 204*043036a2SApple OSS Distributions.Xr connectx 2 , 205*043036a2SApple OSS Distributions.Xr listen 2 , 206*043036a2SApple OSS Distributions.Xr select 2 , 207*043036a2SApple OSS Distributions.Xr socket 2 , 208*043036a2SApple OSS Distributions.Xr compat 5 209*043036a2SApple OSS Distributions.Sh HISTORY 210*043036a2SApple OSS DistributionsThe 211*043036a2SApple OSS Distributions.Fn accept 212*043036a2SApple OSS Distributionsfunction appeared in 213*043036a2SApple OSS Distributions.Bx 4.2 . 214