NAME | SYNOPSIS | API RESTRICTIONS | FEATURES | DESCRIPTION | RETURN VALUES: | ATTRIBUTES | SEE ALSO
#include <sys/types.h> #include <sys/socket.h>int accept(int s, struct sockaddr *addr, int *addrlen);
The function or functions documented here may not be used safely in all application contexts with all APIs provided in the ChorusOS 5.0 product.
See API(5FEA) for details.
POSIX_SOCKETS
The s argument is a socket that was created using socket(2POSIX), bound to an address using bind(2POSIX) and which listens for connections after a call to listen(2POSIX). The accept argument extracts the first connection on the queue of pending connections, creates a new socket with the same properties as 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 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 may not be used to accept more connections. The original socket s remains open.
The addr argument is a result parameter that is filled with the address of the connecting entity, as known to the communications layer. The exact format of the addr parameter is determined by the domain in which the communication takes place. 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(2POSIX) a socket in order to do an accept by selecting it for read.
Upon successful completion, accept returns a non-negative integer that is a descriptor for the accepted socket; otherwise it returns -1 and sets errno to indicate one of the following error conditions:
The argument s is invalid.
The system call has been invoked on a non-listening TCP socket.
The argument s references a file, not a socket.
The referenced socket is not of the type SOCK_STREAM.
The addr parameter is not in a writable part of the process's address space.
The process descriptor table is full.
The system file table is full.
Insufficient buffer space is available. The operation cannot be completed until sufficient resources are freed.
The socket is marked non-blocking, and no connections are present to be accepted.
See attributes(5) for descriptions of the following attributes:
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
---|---|
Interface Stability | Evolving |
MT-level | MT-safe |
NAME | SYNOPSIS | API RESTRICTIONS | FEATURES | DESCRIPTION | RETURN VALUES: | ATTRIBUTES | SEE ALSO