Open System Services System Calls Reference Manual (G06.25+, H06.03+)

System Functions (k - m) listen(2)
NAME
listen - Listens for socket connections and limits the backlog of incoming connections
LIBRARY
G-series native OSS processes: system library
H-series OSS processes: implicit libraries
SYNOPSIS
#include <sys/socket.h>
int listen(
int socket,
int backlog
);
PARAMETERS
socket Species the le descriptor for the socket.
backlog Species the maximum number of outstanding connections. The affect of this
parameter varies according to the connection type and the stack implementation
in use. Refer to the DESCRIPTION section of this reference page for more
information.
DESCRIPTION
The listen() function marks a connection-oriented socket as accepting connections, and limits
the number of outstanding connections in the sockets queue to the value specied by the back-
log parameter.
For AF_INET sockets using conventional TCP/IP, a backlog parameter value of less than or
equal to 0 allows the socket to accept the number of connections congured for the TCP-
LISTEN-QUE-MIN parameter of the transport process. These values can allow up to 5 connec-
tions (the default value for TCP-LISTEN-QUE-MIN).
For AF_INET or AF_INET6 sockets using parallel library TCP/IP or TCP/IPv6, a backlog
parameter value of less than or equal to 0 is ignored. The maximum number of pending connec-
tions is always 5.
For AF_UNIX sockets, a backlog parameter value of less than or equal to 0 makes the socket
refuse any connections. Subsequent attempts to connect to the socket fail and errno is set to
[ECONNREFUSED].
RETURN VALUES
Upon successful completion, the listen() function returns the value 0 (zero). Otherwise, the
value -1 is returned and errno is set to indicate the error.
ERRORS
If any of the following conditions occurs, the listen() function sets errno to the corresponding
value:
[EBADF] The socket parameter is not a valid le descriptor.
[ECONNRESET]
One of the following conditions occurred:
The transport-provider process for this socket is no longer available.
The TCP/IP subsystem for this socket is no longer available.
The connection was forcibly closed by the peer socket.
The socket can only be closed.
527186-003 Hewlett-Packard Company 49