int listen(int sockfd, int backlog);
This syscall marks the passed socket as a passive socket, that is, as a socket
that will be used to accept incoming connection requests using accept
.
The passed socket must be stream based, as these are the only sockets with a true sense of connection.
backlog
is a recommendation as to the maximum length to which the
queue of pending connections for sockfd
may grow. If a connection
request arrives when the queue is full, depending on the protocols involved,
the client may receive an error or the connection may be ignored so that a
later reattempt at connection succeeds.
The syscall returns 0
on success or -1
on failure, with the
following errno:
EINVAL
: Invalid value for backlog.
EBADFD
: The passed FD is not a socket.
ENOTSUPP
: The passed FD is a socket, but it is not a stream socket.