Middleware, development tools, realtime operating system
software and services for superior embedded design


Home
QNX Community Resources
QNX Documentation Library
listen

listen

QNX Software Systems
Developer Resources
Blogs
Board support packages
Foundry27 projects
Forums
Hardware support listing
Online video tutorials
Product documentation
Technical Articles

listen()

Listen for connections on a socket

Synopsis:

#include <sys/socket.h>

int listen( int s, 
            int backlog );

Arguments:

s
The descriptor for the socket that you want to listen on. You can create a socket by calling socket().
backlog
The maximum length that the queue of pending connections may grow to.

Library:

libsocket

Use the -l socket option to qcc to link against this library.

Description:

The listen() function listens for connections on a socket and puts the socket into the LISTEN state. For connections to be accepted, you must:

  1. Create a socket by calling socket().
  2. Indicate a willingness to accept incoming connections and a queue limit for them by calling listen().
  3. Call accept() to accept the connections.

If a connection request arrives with the queue full, the client may receive an error with an indication of ECONNREFUSED. But if the underlying protocol supports retransmission, the request may be ignored so that retries may succeed.


Note: The listen() call applies only to SOCK_STREAM sockets.

Returns:

0
Success.
-1
An error occurred (errno is set).

Errors:

EBADF
Invalid descriptor s.
EOPNOTSUPP
The socket isn't of a type that supports the listen() operation.

Classification:

POSIX 1003.1

Safety:
Cancellation point Yes
Interrupt handler No
Signal handler No
Thread Yes

See also:

accept(), connect(), socket()