Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

listen() - test a socket for pending connections

&pagelevel(3)&pagelevel

#include <sys.socket.h>


Kernighan-Ritchie-C:
int listen(s, backlog);

int s;
int backlog;

ANSI-C:
int listen(int s, int backlog);


Description

The listen() function is supported in the AF_INET and AF_INET6 address families (only for sockets of the type SOCK_STREAM), and in the AF_ISO address family.

The listen() function authorizes socket s to accept connection requests and then tests the socket for pending connection requests. To do this, listen() sets up a queue for incoming connection requests for socket s.

The user can define the maximum number of connection requests that the queue can hold by using the backlog parameter.
Note, however, that SOCKETS(BS2000) does not evaluate the backlog parameter at present and continues to accept connection requests until the maximum number of available sockets have been used.

The following steps are required to enable a task to communicate on a socket with the partner that sends connection requests:

  1. Create a socket (socket()) and bind it (bind())

  2. Specify an incoming connection request queue for the socket with listen().

  3. Accept the connection requests with accept().

  4. In AF_ISO, you also have to send user data or confirm data (CFRM data, sendmsg()) (see also figure 4 in section "Interaction between functions for connection-oriented communications").

You can only use connect() to initiate connections between two sockets of the AF_ISO address family, or between two sockets of the AF_INET address family or AF_INET6 address family, or between a socket of the AF_INET address family and a socket of the AF_INET6 address family.

Therefore, if you are using all the address families, you should set up a listen() socket of the AF_ISO address family, as well as a listen() socket of the AF_INET or AF_INET6 address family. This ensures that connections to every supported address family can be set up.

Return value

0:

If successful.

-1:

If errors occur. errno is set to indicate the error.

Errors indicated by errno

EBADF

The s parameter is not a valid descriptor.

EISCONN

The socket already has a connection.

EOPNOTSUPP

The socket is not of type SOCK_STREAM and is not supported by listen().

See also

accept(), connect(), socket()