|
Description
The listen() function enables socket s for accepting connection requests. To do this, listen() sets up a queue for incoming connection requests for socket s. The backlog parameter defines the maximum number of connection requests that the queue can hold. The value of backlog is limited to a maximum of 50.
The listen() function can only be called for type SOCK_STREAM sockets.
The following steps are required to enable a process to communicate over a socket with the partner who sends connection requests:
Create and bind a socket using socket() and bind().
Set up an incoming connection requests queue for the socket using listen().
Accept the connection requests using accept().
If a connection request arrives and the queue is full, the socket that sent the connection request receives the error message ECONNREFUSED or ETIMEDOUT.
Return value
0:
If successful.
-1:
If errors occur. errno is set to indicate the error.
Errors
EBADF
The s parameter is not a valid descriptor.
ENOTSOCK
Descriptor s references a file and not a socket.
EOPNOTSUPP
The socket type is not supported by listen().