Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

listen() - test a socket for pending connections

&pagelevel(4)&pagelevel

#include <sys/socket.h>

int listen(int s, int backlog);

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:

  1. Create and bind a socket using socket() and bind().

  2. Set up an incoming connection requests queue for the socket using listen().

  3. 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().

See also

accept(), connect(), socket()