listen(3sock)


listen -- listen for connections on a socket

Synopsis

cc [options] file -lsocket -lnsl
#include <sys/socket.h> 

int listen(int socket, int backlog);

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 or SOCK_SEQPACKET.

The backlog parameter defines the maximum length the queue of pending connections may grow to. If a connection request arrives with the queue full, the client will receive an error with an indication of ECONNREFUSED.

If listen is called with backlog less than 0, the length of the socket's listen queue is set to 0. If backlog exceeds the maximum queue length, the length of the socket's listen queue will be set to the maximum supported value.

Files

/usr/lib/locale/locale/LC_MESSAGES/uxnsl

Return values

A value of 0 indicates success; -1 indicates an error.

Errors

The call fails if:

EBADF
socket is not a valid descriptor.

ENOTSOCK
socket is not a socket.

EOPNOTSUPP
The socket is not of a type that supports the operation listen.

EINVAL
The socket is already connected or has been shut down.

EDESTADDRREQ
The socket is not bound to a local address, and the protocol does not support listening on an unbound socket.

ENOBUFS
System resources are insufficient to complete the call.

References

accept(3sock), connect(3sock), socket(3sock)
30 January 1998
© 1998 The Santa Cruz Operation, Inc. All rights reserved.