listen

Prepares a socket to accept a connection.

Library:LibC
Standard:ANSI
Service:Networking

Syntax

  #include <sys/socket.h> 
   
  int listen (
     int   s,   
     int   backlog);
  

Parameters

s

(IN) Specifies the socket file handle that is to be prepared to accept a connection.

backlog

(IN) Specifies the maximum length for the queue of pending connections (the value of SOMAXCONN which is set to 5).

Return Values

If successful, returns 0. Otherwise, returns -1 and sets errno to one of the following:

Decimal

Constant

Description

4

EBADF

The socket parameter is not a valid socket file handle.

38

ENOTSOCK

The socket parameter does not reference a socket file handle.

42

ENOPROTOOPT

The option is unknown at the level indicated.

45

EOPNOTSUPP

The socket does not support this function.

Remarks

The socket function creates a socket, the listen function prepares the socket to accept incoming connections and specifies a queue limit for incoming connections, and the accept function accepts the connection.

The listen function works for sockets only of type SOCK_STREAM and can be called to create a passive socket.

If a connect request arrives when the queue is full, the client receives an ECONNREFUSED error.

See Also