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