1LISTEN(3P)                 POSIX Programmer's Manual                LISTEN(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       listen - listen for socket connections and limit the queue of  incoming
13       connections
14

SYNOPSIS

16       #include <sys/socket.h>
17
18       int listen(int socket, int backlog);
19
20

DESCRIPTION

22       The listen() function shall mark a connection-mode socket, specified by
23       the socket argument, as accepting connections.
24
25       The backlog argument provides a hint to the  implementation  which  the
26       implementation shall use to limit the number of outstanding connections
27       in the socket's listen queue. Implementations may  impose  a  limit  on
28       backlog  and  silently  reduce  the specified value. Normally, a larger
29       backlog argument value shall result in a larger or equal length of  the
30       listen  queue.   Implementations  shall support values of backlog up to
31       SOMAXCONN, defined in <sys/socket.h>.
32
33       The implementation may include incomplete  connections  in  its  listen
34       queue. The limits on the number of incomplete connections and completed
35       connections queued may be different.
36
37       The implementation may have an upper limit on the length of the  listen
38       queue-either  global  or  per accepting socket. If backlog exceeds this
39       limit, the length of the listen queue is set to the limit.
40
41       If listen() is called with a backlog argument value that is  less  than
42       0,  the  function behaves as if it had been called with a backlog argu‐
43       ment value of 0.
44
45       A backlog argument of 0 may allow the socket to accept connections,  in
46       which  case the length of the listen queue may be set to an implementa‐
47       tion-defined minimum value.
48
49       The socket in use may require the process to  have  appropriate  privi‐
50       leges to use the listen() function.
51

RETURN VALUE

53       Upon  successful  completions,  listen()  shall return 0; otherwise, -1
54       shall be returned and errno set to indicate the error.
55

ERRORS

57       The listen() function shall fail if:
58
59       EBADF  The socket argument is not a valid file descriptor.
60
61       EDESTADDRREQ
62
63              The socket is not bound to a local  address,  and  the  protocol
64              does not support listening on an unbound socket.
65
66       EINVAL The socket is already connected.
67
68       ENOTSOCK
69              The socket argument does not refer to a socket.
70
71       EOPNOTSUPP
72              The socket protocol does not support listen().
73
74
75       The listen() function may fail if:
76
77       EACCES The calling process does not have the appropriate privileges.
78
79       EINVAL The socket has been shut down.
80
81       ENOBUFS
82              Insufficient  resources  are available in the system to complete
83              the call.
84
85
86       The following sections are informative.
87

EXAMPLES

89       None.
90

APPLICATION USAGE

92       None.
93

RATIONALE

95       None.
96

FUTURE DIRECTIONS

98       None.
99

SEE ALSO

101       accept(),  connect(),  socket(),  the  Base   Definitions   volume   of
102       IEEE Std 1003.1-2001, <sys/socket.h>
103
105       Portions  of  this text are reprinted and reproduced in electronic form
106       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
107       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
108       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
109       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
110       event of any discrepancy between this version and the original IEEE and
111       The  Open Group Standard, the original IEEE and The Open Group Standard
112       is the referee document. The original Standard can be  obtained  online
113       at http://www.opengroup.org/unix/online.html .
114
115
116
117IEEE/The Open Group                  2003                           LISTEN(3P)
Impressum