.TH listen() "" "" "Sockets Function (libsocket)"
.PC "Listen for a connection on a socket"
.B "#include <sys/socket.h>"
\fBint listen(\fIsocket\^\fB, \fIbacklog\^\fB)\fR
\fBint \fIsocket\^\fB, int \fIbacklog\^\fB;\fR
.PP
Function
.B listen()
``listens'' for a connection on
.IR socket .
It also signals the system your process's willingness to accept a
connection on that socket.
This function applies only to sockets of type
.B SOCK_STREAM
or
.BR SOCK_SEQPACKET .
.PP
.I socket
is a file descriptor that identifies the socket in question.
It must have been returned by a call to
.BR socket() .
.I backlog
defines the maximum length to which the queue of pending connections may grow.
As of this writing,
.I backlog
is limited to a maximum of five.
If a connection request arrives with the queue full, the client may
receive an error with an indication of
.BR ECONNREFUSED ;
or if the underlying protocol supports retransmission,
the request may be ignored so that retries may succeed.
.PP
If all goes well,
.B listen()
returns zero.
If an error occurs, it returns \-1 and sets
.B errno
to an appropriate value.
The following lists the errors that can occur, by the value to which
.B listen()
sets
.BR errno :
.IP \fBEBADF\fR
.I socket
is not a valid descriptor.
.IP \fIENOTSOCK\fR
.I socket
does not identify a socket.
.IP \fBEOPNOTSUPP\fR
.I socket
is not of a type that supports
.BR listen() .
.SH Example
For an example of this function, see the Lexicon entry for
.BR libsocket .
.SH "See Also"
.Xr "accept()," accept
.Xr "connect()," connect
.Xr "libsocket," libsocket
.Xr "socket()" socket
