Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

bind(2N)

connect(2N)

listen(2N)

select(2N)

socket(2N)




accept(2N) accept(2N)
NAME accept - accept a connection on a socket SYNOPSIS #include <sys/types.h> #include <sys/socket.h> int accept(s, addr, addrlen) int s; struct sockaddr *addr; int *addrlen; DESCRIPTION The argument s is a socket which has been created with socket(2N), bound to an address with bind(2N), and is listening for connections after a listen(2N). accept ex- tracts the first connection on the queue of pending connec- tions, creates a new socket with the same properties of s and allocates a new file descriptor for the socket. If no pending connections are present on the queue, and the socket is not marked as nonblocking, accept blocks the caller until a connection is present. If the socket is marked nonblock- ing and no pending connections are present on the queue, ac- cept returns an error as described below. The accepted socket may not be used to accept more connections. The ori- ginal socket s remains open. The argument addr is a result parameter which is filled in with the address of the connecting entity, as known to the communications layer. The exact format of the addr parame- ter is determined by the domain in which the communication is occurring. The addrlen is a value-result parameter; it should initially contain the amount of space pointed to by addr; on return it will contain the actual length (in bytes) of the address returned. This call is used with connection-based socket types, currently with SOCK_STREAM. It is possible to select(2N) a socket for the purposes of doing an accept by selecting it for read. RETURN VALUE The call returns -1 on error. If it succeeds it returns a non-negative integer which is a descriptor for the accepted socket. ERRORS accept will fail if: [EBADF] The descriptor is invalid. [ENOTSOCK] The descriptor references a file, not a socket. April, 1990 1



accept(2N) accept(2N)
[EOPNOTSUPP] The referenced socket is not of type SOCK_STREAM. [EFAULT] The addr parameter is not in a writable part of the user address space. [EWOULDBLOCK] The socket is marked nonblocking and no connections are present to be accepted. SEE ALSO bind(2N), connect(2N), listen(2N), select(2N), socket(2N). 2 April, 1990

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026