NAME

accept - accept a connection on a socket

SYNOPSIS

#include <sys/types.h>
#include <sys/socket.h>

int accept(int s , struct sockaddr *addr , socklen_t *addrlen );

DESCRIPTION

The argument s is a socket that has been created with socket() and bound to an address with bind(), and that is listening for connections after a call to listen(). accept() extracts the first connection on the queue of pending connections, creates a new socket with the properties of s, and allocates a new file descriptor, ns , for the socket. If no pending connections are present on the queue and the socket is not marked as non-blocking, accept() 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, accept() returns an error as described below.

The accepted socket, ns , is used to read and write data to and from the socket that connected to ns; it is not used to accept more connections. The original socket (s) remains open for accepting further connections.

The argument addr 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 addr parameter is determined by the domain in which the communication occurs.

addrlen is a value-result parameter. Initially, it contains the amount of space pointed to by addr ; on return it contains the length in bytes of the address returned.

accept() is used with connection-based socket types, currently with SOCK_STREAM.

It is NOT possible to select() or pool() a socket for the purpose of an accept() in the system.

RETURN VALUES

accept() returns -1 on error. If it succeeds, it returns a non-negative integer that is a descriptor for the accepted socket.

ERRORS

This function is a member of Unison's IOLIB family of functions. IOLIB is implemented as a message passing and generalized interface layer. Each Unison I/O server is responsible for its own error reporting.

For an exact list of error codes returned by a particular server, refer to that server's documentation in the Unison Programmer's Guide for each specific platform.

Servers may implement these errors codes in response to this function.

accept() will fail if:

EAGAIN or EWOULDBLOCK
The socket is marked as non-blocking and no connections are present to be accepted.
EBADF
The descriptor is invalid.
ECONNABORTED
A connection has been aborted.
ENOMEM
There was insufficient user memory available to complete the operation.
ENOTSOCK
The descriptor does not reference a socket.
ENFILE
The maximum number of file descriptors in the system are already open.
EINVAL
The socket is not accepting connections.
EOPNOTSUPP
The socket type of the specified socket does not support accepting connections.
EPROTO
A protocol error has occurred; for example, the protocol stack has not been initialized.

SEE ALSO

bind(), connect(), listen(), socket()



< Copyright Rowebots Research Inc. and Multiprocessor Toolsmiths Inc. 1987-2011 >