aboutsummaryrefslogtreecommitdiffstats
path: root/man-pages-posix-2003/man3p/listen.3p
blob: 840c74c7cf17f7b6aa7d48438348c222cf3ebf80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved 
.TH "LISTEN" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual"
.\" listen 
.SH PROLOG
This manual page is part of the POSIX Programmer's Manual.
The Linux implementation of this interface may differ (consult
the corresponding Linux manual page for details of Linux behavior),
or the interface may not be implemented on Linux.
.SH NAME
listen \- listen for socket connections and limit the queue of incoming
connections
.SH SYNOPSIS
.LP
\fB#include <sys/socket.h>
.br
.sp
int listen(int\fP \fIsocket\fP\fB, int\fP \fIbacklog\fP\fB);
.br
\fP
.SH DESCRIPTION
.LP
The \fIlisten\fP() function shall mark a connection-mode socket, specified
by the \fIsocket\fP argument, as accepting
connections.
.LP
The \fIbacklog\fP argument provides a hint to the implementation which
the implementation shall use to limit the number of
outstanding connections in the socket's listen queue. Implementations
may impose a limit on \fIbacklog\fP and silently reduce the
specified value. Normally, a larger \fIbacklog\fP argument value shall
result in a larger or equal length of the listen queue.
Implementations shall support values of \fIbacklog\fP up to SOMAXCONN,
defined in \fI<sys/socket.h>\fP.
.LP
The implementation may include incomplete connections in its listen
queue. The limits on the number of incomplete connections
and completed connections queued may be different.
.LP
The implementation may have an upper limit on the length of the listen
queue-either global or per accepting socket. If
\fIbacklog\fP exceeds this limit, the length of the listen queue is
set to the limit.
.LP
If \fIlisten\fP() is called with a \fIbacklog\fP argument value that
is less than 0, the function behaves as if it had been
called with a \fIbacklog\fP argument value of 0.
.LP
A \fIbacklog\fP argument of 0 may allow the socket to accept connections,
in which case the length of the listen queue may be
set to an implementation-defined minimum value.
.LP
The socket in use may require the process to have appropriate privileges
to use the \fIlisten\fP() function.
.SH RETURN VALUE
.LP
Upon successful completions, \fIlisten\fP() shall return 0; otherwise,
-1 shall be returned and \fIerrno\fP set to indicate
the error.
.SH ERRORS
.LP
The \fIlisten\fP() function shall fail if:
.TP 7
.B EBADF
The \fIsocket\fP argument is not a valid file descriptor.
.TP 7
.B EDESTADDRREQ
.sp
The socket is not bound to a local address, and the protocol does
not support listening on an unbound socket.
.TP 7
.B EINVAL
The \fIsocket\fP is already connected.
.TP 7
.B ENOTSOCK
The \fIsocket\fP argument does not refer to a socket.
.TP 7
.B EOPNOTSUPP
The socket protocol does not support \fIlisten\fP().
.sp
.LP
The \fIlisten\fP() function may fail if:
.TP 7
.B EACCES
The calling process does not have the appropriate privileges.
.TP 7
.B EINVAL
The \fIsocket\fP has been shut down.
.TP 7
.B ENOBUFS
Insufficient resources are available in the system to complete the
call.
.sp
.LP
\fIThe following sections are informative.\fP
.SH EXAMPLES
.LP
None.
.SH APPLICATION USAGE
.LP
None.
.SH RATIONALE
.LP
None.
.SH FUTURE DIRECTIONS
.LP
None.
.SH SEE ALSO
.LP
\fIaccept\fP(), \fIconnect\fP(), \fIsocket\fP(), the Base Definitions
volume of IEEE\ Std\ 1003.1-2001, \fI<sys/socket.h>\fP
.SH COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group. In the
event of any discrepancy between this version and the original IEEE and
The Open Group Standard, the original IEEE and The Open Group Standard
is the referee document. The original Standard can be obtained online at
http://www.opengroup.org/unix/online.html .