listen()--Invite Incoming Connections Requests


  Syntax
 #include <sys/socket.h>

 int listen(int socket_descriptor,
           int back_log)

  Service Program Name: QSOSRV1

  Default Public Authority: *USE

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

Authorities

No authorization is required.


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_INET6, 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:

  • A connect() has been issued on the socket pointed to by the socket_descriptor parameter.

  • The socket_descriptor parameter points to a socket with an address family of AF_UNIX that has not been bound to an address.

[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).

Start of V7R1 changes[EPERM] The operation is not permitted.

A user exit program registered for the exit point, QIBM_QSO_LISTEN, has denied the listen() API successful completion.

End of V7R1 changes
[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. If the back_log parameter specifies a value greater than the maximum {SOMAXCONN} allowed, the specified value will be ignored and SOMAXCONN will be used. If the back_log parameter specifies a negative value, the specified value will be ignored and zero will be used.

  4. 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:


  5. When you develop in C-based languages and an application is compiled with the _XOPEN_SOURCE macro defined to the value 520 or greater, the listen() API is mapped to qso_listen98().
  6. Start of V7R1 changes
  7. A user exit point, QIBM_QSO_LISTEN, exists to optionally allow or deny the listen() API to successfully complete based on the return code from the registered user exit program. For more information refer to Sockets listen() API Exit Program.
  8. End of V7R1 changes

Related Information



API introduced: V3R1

[ Back to top | UNIX-Type APIs | APIs by category ]