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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

EXAMPLES

85       None.
86

APPLICATION USAGE

88       None.
89

RATIONALE

91       None.
92

FUTURE DIRECTIONS

94       None.
95

SEE ALSO

97       accept(), connect(), socket()
98
99       The Base Definitions volume of POSIX.1‐2017, <sys_socket.h>
100
102       Portions of this text are reprinted and reproduced in  electronic  form
103       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
104       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
105       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
106       Electrical and Electronics Engineers, Inc and The Open Group.   In  the
107       event of any discrepancy between this version and the original IEEE and
108       The Open Group Standard, the original IEEE and The Open Group  Standard
109       is  the  referee document. The original Standard can be obtained online
110       at http://www.opengroup.org/unix/online.html .
111
112       Any typographical or formatting errors that appear  in  this  page  are
113       most likely to have been introduced during the conversion of the source
114       files to man page format. To report such errors,  see  https://www.ker
115       nel.org/doc/man-pages/reporting_bugs.html .
116
117
118
119IEEE/The Open Group                  2017                           LISTEN(3P)
Impressum