listen(3)

NAME
listen - listen for connections on a socket

SYNOPSIS
#include <sys/socket.h>

int listen(int s, int backlog);

DESCRIPTION
To accept connections, a socket is first created with socket(3), a queue for incoming connections is specified with listen(3) and then connections are accepted with accept(3). listen applies only to unconnected sockets of type SOCK_STREAM. For sockets in the address family AF_UNIX the socket must be bound to an address with bind(3) before connection establishment can continue, otherwise an EDESTADDRREQ error is returned.

The listen queue is established for the socket specified by the s parameter, which is a socket descriptor.

backlog defines the maximum allowable length of the queue for pending connections. If a connection request arrives when the queue is full, the client receives an ETIMEDOUT error.

RETURN VALUE
If the call is successful, 0 is returned. If the call fails, -1 is returned and an error code is stored in errno.

DIAGNOSTICS
listen fails if:

[EBADF]
    The argument s is not a valid descriptor.

[EDESTADDRREQ]
    No bind address was established.

[EOPNOTSUPP]
    The socket is not of a type that supports the listen operation.

[EINVAL]
    The socket has been shut down or is already connected. The argument s is not a socket.

SEE ALSO
accept(3), connect(3), socket(3).