Jump to: navigation, search

Table of Contents >> Programmer's Reference

#include <trsocket.h>

int listen (
int socketDescriptor,
int backLog

Function Description

To accept connections, a socket is first created with socket(). A backlog for incoming connections is specified with listen() and then the connections are accepted with accept(). The listen() call applies only to sockets of type SOCK_STREAM. The backLog parameter defines the maximum length the queue of pending connections may grow to. If a connection request arrives with the queue full, and the underlying protocol supports retransmission, the connection request may be ignored so that retries may succeed. For AF_INET sockets, TCP will retry the connection. If the backlog is not cleared by the time the TCP times out, connect() will fail with TM_ETIMEDOUT.


  • socketDescriptor
    The socket descriptor to listen on.
  • backLog
    The maximum number of outstanding connections allowed on the socket.

Return Values


Note Note: TM_SOCKET_ERROR means that this socket call has failed and the errorCode has been set on the socket itself.

To retrieve the socket error the user must call tfGetSocketError(socketDescriptor).

Possible socket errors

    The address is currently used by another socket.
    The socket descriptor is invalid.
    The socket is not of a type that supports the listen() operation.

Table of Contents >> Programmer's Reference