]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/listen.2
s/parameter/argument/ when talking about the things given
[thirdparty/man-pages.git] / man2 / listen.2
1 .\" Copyright (c) 1983, 1991 The Regents of the University of California.
2 .\" and Copyright (C) 2007, Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" All rights reserved.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
13 .\" 3. All advertising materials mentioning features or use of this software
14 .\" must display the following acknowledgement:
15 .\" This product includes software developed by the University of
16 .\" California, Berkeley and its contributors.
17 .\" 4. Neither the name of the University nor the names of its contributors
18 .\" may be used to endorse or promote products derived from this software
19 .\" without specific prior written permission.
20 .\"
21 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 .\" SUCH DAMAGE.
32 .\"
33 .\" $Id: listen.2,v 1.6 1999/05/18 14:10:32 freitag Exp $
34 .\"
35 .\" Modified Fri Jul 23 22:07:54 1993 by Rik Faith <faith@cs.unc.edu>
36 .\" Modified 950727 by aeb, following a suggestion by Urs Thuermann
37 .\" <urs@isnogud.escape.de>
38 .\" Modified Tue Oct 22 08:11:14 EDT 1996 by Eric S. Raymond <esr@thyrsus.com>
39 .\" Modified 1998 by Andi Kleen
40 .\" Modified 11 May 2001 by Sam Varshavchik <mrsam@courier-mta.com>
41 .\"
42 .\"
43 .TH LISTEN 2 2007-12-28 "Linux" "Linux Programmer's Manual"
44 .SH NAME
45 listen \- listen for connections on a socket
46 .SH SYNOPSIS
47 .nf
48 .BR "#include <sys/types.h>" " /* See NOTES */"
49 .br
50 .B #include <sys/socket.h>
51 .sp
52 .BI "int listen(int " sockfd ", int " backlog );
53 .fi
54 .SH DESCRIPTION
55 .BR listen ()
56 marks the socket referred to by
57 .I sockfd
58 as a passive socket, that is, as a socket that will
59 be used to accept incoming connection requests using
60 .BR accept (2).
61
62 The
63 .I sockfd
64 argument is a file descriptor that refers to a socket of type
65 .B SOCK_STREAM
66 or
67 .BR SOCK_SEQPACKET .
68
69 The
70 .I backlog
71 argument defines the maximum length
72 to which the queue of pending connections for
73 .I sockfd
74 may grow.
75 If a connection request arrives when the queue is full, the client
76 may receive an error with an indication of
77 .B ECONNREFUSED
78 or, if the underlying protocol supports retransmission, the request may be
79 ignored so that a later reattempt at connection succeeds.
80 .SH "RETURN VALUE"
81 On success, zero is returned.
82 On error, \-1 is returned, and
83 .I errno
84 is set appropriately.
85 .SH ERRORS
86 .TP
87 .B EADDRINUSE
88 Another socket is already listening on the same port.
89 .TP
90 .B EBADF
91 The argument
92 .I sockfd
93 is not a valid descriptor.
94 .TP
95 .B ENOTSOCK
96 The argument
97 .I sockfd
98 is not a socket.
99 .TP
100 .B EOPNOTSUPP
101 The socket is not of a type that supports the
102 .BR listen ()
103 operation.
104 .SH "CONFORMING TO"
105 4.4BSD, POSIX.1-2001.
106 The
107 .BR listen ()
108 function call first appeared in 4.2BSD.
109 .SH NOTES
110 To accept connections, the following steps are performed:
111 .RS 4
112 .IP 1. 4
113 A socket is created with
114 .BR socket (2).
115 .IP 2.
116 The socket is bound to a local address using
117 .BR bind (2),
118 so that other sockets may be
119 .BR connect (2)ed
120 to it.
121 .IP 3.
122 A willingness to accept incoming connections and a queue limit for incoming
123 connections are specified with
124 .BR listen ().
125 .IP 4.
126 Connections are accepted with
127 .BR accept (2).
128 .RE
129 .PP
130 POSIX.1-2001 does not require the inclusion of
131 .IR <sys/types.h> ,
132 and this header file is not required on Linux.
133 However, some historical (BSD) implementations required this header
134 file, and portable applications are probably wise to include it.
135
136 The behavior of the
137 .I backlog
138 argument on TCP sockets changed with Linux 2.2.
139 Now it specifies the queue length for
140 .I completely
141 established sockets waiting to be accepted,
142 instead of the number of incomplete connection requests.
143 The maximum length of the queue for incomplete sockets
144 can be set using the
145 .I tcp_max_syn_backlog
146 sysctl.
147 When syncookies are enabled there is no logical maximum
148 length and this sysctl setting is ignored.
149 See
150 .BR tcp (7)
151 for more information.
152
153 If the
154 .I backlog
155 argument is greater than the value in
156 .IR /proc/sys/net/core/somaxconn ,
157 then it is silently truncated to that value;
158 the default value in this file is 128.
159 In kernels before 2.4.25, this limit was a hard coded value,
160 .BR SOMAXCONN ,
161 with the value 128.
162 .\" The following is now rather historic information (MTK, Jun 05)
163 .\" Don't rely on this value in portable applications since BSD
164 .\" (and some BSD-derived systems) limit the backlog to 5.
165 .SH EXAMPLE
166 See
167 .BR bind (2).
168 .SH "SEE ALSO"
169 .BR accept (2),
170 .BR bind (2),
171 .BR connect (2),
172 .BR socket (2)