Skip site navigation (1)Skip section navigation (2)

FreeBSD Man Pages

Man Page or Keyword Search:
Man Architecture
Apropos Keyword Search (all sections) Output format
home | help
LISTEN(2)                 FreeBSD System Calls Manual                LISTEN(2)

NAME
     listen - listen for connections on a socket

SYNOPSIS
     #include <sys/types.h>
     #include <sys/socket.h>

     int
     listen(int s, int backlog);

DESCRIPTION
     To accept connections, a socket is first created with socket(2), a
     willingness to accept incoming connections and a queue limit for incoming
     connections are specified with listen(), and then the connections are
     accepted with accept(2).  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 may receive an error with an indication of ECONNREFUSED,
     or, if the underlying protocol supports retransmission, the request may
     be ignored so that retries may succeed.

     The sysctl(3) MIB variable ``kern.ipc.somaxconn'' specifies a hard limit
     on backlog; if a  value greater than kern.ipc.somaxconn or less than zero
     is specified, backlog is silently forced to kern.ipc.somaxconn.

IMPLEMENTATION NOTES
     In the non-threaded library listen() is implemented as the listen
     syscall.

     In the threaded library, the listen syscall is assembled to
     _thread_sys_listen() and listen() is implemented as a function which
     locks s for read and write, then calls _thread_sys_listen().  Before
     returning, listen() unlocks s.

RETURN VALUES
     A 0 return value indicates success; -1 indicates an error.

ERRORS
     Listen() will fail if:

     [EBADF]       The argument s is not a valid descriptor.

     [ENOTSOCK]    The argument s is not a socket.

     [EOPNOTSUPP]  The socket is not of a type that supports the operation
                   listen().

SEE ALSO
     accept(2), connect(2), socket(2), sysctl(3), sysctl(8)

HISTORY
     The listen() function call appeared in 4.2BSD.  The ability to configure
     the maximum backlog at run-time, and to use a negative backlog to request
     the maximum allowable value, was introduced in FreeBSD 2.2.

BSD 4.2                        November 3, 1995                        BSD 4.2

NAME | SYNOPSIS | DESCRIPTION | IMPLEMENTATION NOTES | RETURN VALUES | ERRORS | SEE ALSO | HISTORY

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=listen&sektion=2&manpath=FreeBSD+4.0-RELEASE>

home | help