Accepts a connection from a remote host.
#include <sys/socket.h> int accept ( int s, struct sockaddr *addr, size_t *len);
(IN) Specifies a socket file handle that is waiting for a connection.
(OUT) Points to the location for the address that is assigned to an unbound socket. For IPv4, addr points to a sockaddr structure; for IPv6, to a sockaddr_in6 structure. The first two bytes in the structures identify the protocol family, and hence the structure.
(IN/OUT) Points to the amount of space pointed to by addr. Returns the actual length (in bytes) of addr.
If successful, returns an integer handle for the accepted socket. Otherwise, returns -1 and sets errno to one of the following:
The accept function is used with connection-based socket types (SOCK_STREAM).
The s parameter must reference a socket that was created with socket, that has been bound to an address with bind, and that has issued a successful call to listen. The accept function then accepts the connection on a socket, and the original socket is returned to a listening state. It extracts the first connection from the queue pending connections, creates a new socket with the same properties of s, and allocates a new file handle for the socket.
If there are no pending connections, accept behaves in the following manner:
If the socket is not marked as nonblocking, accept blocks the caller until a connection is present.
If the socket is marked nonblocking and there are no pending connections, accept returns an error.
The accepted socket handle cannot be used to accept more connections. The original socket remains open and continues to listen for connections.