listen()--Invite Incoming Connections Requests



Syntax

#include <sys/socket.h>

int listen(int socket_descriptor,
           int back_log)


Threadsafe: Yes

The listen() function is used to indicate a willingness to accept incoming connection requests. If a listen() is not done, incoming connections are silently discarded.

Parameters

socket_descriptor
(Input) The descriptor of the socket that is to be prepared to receive incoming connection requests.

back_log
(Input) The maximum number of connection requests that can be queued before the system starts rejecting incoming requests. The maximum number of connection requests that can be queued is defined by {SOMAXCONN} (defined in <sys/socket.h>).

Return Value

listen() returns an integer. Possible values are:

Error Conditions

When listen() fails, errno can be set to one of the following:

[EADDRNOTAVAIL]
Address not available.

The socket has an address family of AF_INET or AF_NS, the socket was not bound, and the system tried to bind the socket but could not because a port was not available.

[EBADF]
Descriptor not valid.
[EINVAL]
Parameter not valid.

This error code indicates one of the following:

[EIO]
Input/output error.
[ENOBUFS]
There is not enough buffer space for the requested operation.
[ENOTSOCK]
The specified descriptor does not reference a socket.
[EOPNOTSUPP]
Operation not supported.

The socket_descriptor parameter points to a socket that does not support listen(). listen() is only supported on sockets that are using a connection-oriented protocol (socket type of SOCK_STREAM).

[EUNKNOWN]
Unknown system state.
[EUNATCH]
The protocol required to support the specified address family is not available at this time.

Error Messages

CPE3418 E
Possible APAR condition or hardware failure.
CPF9872 E
Program or service program &1 in library &2 ended. Reason code &3.
CPFA081 E
Unable to set return value or error code.

Usage Notes

  1. If the socket is not bound to an address and the address family is:

  2. listen() can be issued multiple times for a particular socket.

  3. The optimal setting of the listen() back_log value is dependent on the following factors:

    Also, to help you determine how much main storage is consumed by a connection request in the listen() back_log, consider the following:

  4. For AF_TELEPHONY sockets, the back_log value is ignored.

Related Information


Top | Sockets APIs | APIs by category


[Information Center Home Page | Feedback ] [Legal | AS/400 Glossary]