MAN page from Mandrake Other man-pages-gz-1.21-2.noarch.rpm
ACCEPT
Section: Linux Programmer's Manual (2)
Updated: 24 July 1993
Index NAME
accept - accept a connection on a socket
SYNOPSIS
#include <sys/types.h>#include <sys/socket.h>
int accept(int s, struct sockaddr *addr, int *addrlen);
DESCRIPTION
The argument
sis a socket that has been created with
socket(2),bound to an address with
bind(2),and is listening for connections after a
listen(2).The
acceptfunction extracts the first connection request on the queue of pendingconnections, creates a new socket with the same properties of
sand allocates a new file descriptor for the socket. If no pendingconnections are present on the queue, and the socket is not marked asnon-blocking,
acceptblocks the caller until a connection is present. If the socket is markednon-blocking and no pending connections are present on the queue,
acceptreturns an error as described below. The accepted socket may not be usedto accept more connections. The original socket
sremains open.
The argumentaddris a result parameter that is filled in with the address of the connectingentity, as known to the communications layer. The exact format of theaddrparameter is determined by the domain in which the communication isoccurring. Theaddrlenis a value-result parameter; it should initially contain theamount of space pointed to byaddr;on return it will contain the actual length (in bytes) of the addressreturned. This call is used with connection-based socket types, currentlywithSOCK_STREAM.
It is possible toselect(2)a socket for the purposes of doing anacceptby selecting it for read.
For certain protocols which require an explicit confirmation,such asISOorDATAKIT,acceptcan be thought of as merely dequeuing the next connection request and notimplying confirmation. Confirmation can be implied by a normal read orwrite on the new file descriptor, and rejection can be implied by closingthe new socket.
One can obtain user connection request data without confirmingthe connection by issuing a recvmsg(2)call with anmsg_iovlenof 0 and a non-zeromsg_controllen,or by issuing agetsockopt(2)request. Similarly, one can provide user connection rejection informationby issuing asendmsg(2)call with providing only the control information,or by callingsetsockopt(2).
RETURN VALUES
The call returns -1 on error. If it succeeds, it returns a non-negativeinteger that is a descriptor for the accepted socket.
ERRORS
The BSD man page documents five possible error returns.
- EBADF
- The descriptor is invalid.
- ENOTSOCK
- The descriptor references a file, not a socket.
- EOPNOTSUPP
- The referenced socket is not of typeSOCK_STREAM.
- EFAULT
- Theaddrparameter is not in a writable part of the user address space.
- EWOULDBLOCK
- The socket is marked non-blocking and no connections arepresent to be accepted.
Various Linux kernels can return various other errors such asEMFILE,EINVAL,ENOSR,ENOBUFS,EAGAIN,EPERM,ECONNABORTED,ESOCKTNOSUPPORT,EPROTONOSUPPORT,ETIMEDOUT,ERESTARTSYS.
CONFORMING TO
SVr4, 4.4BSD (the
acceptfunction first appeared in BSD 4.2).IRIX documents additional errors EMFILE and ENFILE.Solaris documents additional errors EINTR, ENODEV, ENOMEM,ENOSR and EPROTO.
SEE ALSO
bind(2),
connect(2),
listen(2),
select(2),
socket(2)
Index
- NAME
- SYNOPSIS
- DESCRIPTION
- RETURN VALUES
- ERRORS
- CONFORMING TO
- SEE ALSO
This document was created byman2html,using the manual pages.