]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/listen.2
Wrapped long lines, wrapped at sentence boundaries; stripped trailing
[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.\"
41.TH LISTEN 2 1993-07-23 "BSD Man Page" "Linux Programmer's Manual"
42.SH NAME
43listen \- listen for connections on a socket
44.SH SYNOPSIS
45.B #include <sys/socket.h>
46.sp
3e6b03a0 47.BI "int listen(int " sockfd ", int " backlog );
fea681da
MK
48.SH DESCRIPTION
49To accept connections, a socket is first created with
50.BR socket (2),
51a willingness to accept incoming connections and a queue limit for incoming
52connections are specified with
884dda7b 53.BR listen (),
fea681da
MK
54and then the connections are
55accepted with
56.BR accept (2).
57The
884dda7b 58.BR listen ()
fea681da
MK
59call applies only to sockets of type
60.B SOCK_STREAM
61or
62.BR SOCK_SEQPACKET .
63.PP
64The
65.I backlog
66parameter defines the maximum length the queue of pending connections may
c13182ef
MK
67grow to.
68If a connection request arrives with the queue full the client
fea681da
MK
69may receive an error with an indication of
70.B ECONNREFUSED
71or, if the underlying protocol supports retransmission, the request may be
72ignored so that retries succeed.
73.SH NOTES
c13182ef
MK
74The behaviour of the
75.I backlog
fea681da 76parameter on TCP sockets changed with Linux 2.2.
c13182ef
MK
77Now it specifies the queue length for
78.I completely
fea681da 79established sockets waiting to be accepted, instead of the number of incomplete
c13182ef
MK
80connection requests.
81The maximum length of the queue for incomplete sockets
82can be set using the
fea681da
MK
83.B tcp_max_syn_backlog
84sysctl.
c13182ef 85When syncookies are enabled there is no logical maximum
fea681da 86length and this sysctl setting is ignored.
c13182ef 87See
fea681da
MK
88.BR tcp (7)
89for more information.
fea681da 90.SH "RETURN VALUE"
c13182ef
MK
91On success, zero is returned.
92On error, \-1 is returned, and
fea681da
MK
93.I errno
94is set appropriately.
95.SH ERRORS
96.TP
97.B EADDRINUSE
98Another socket is already listening on the same port.
99.TP
100.B EBADF
101The argument
3e6b03a0 102.I sockfd
fea681da
MK
103is not a valid descriptor.
104.TP
105.B ENOTSOCK
106The argument
3e6b03a0 107.I sockfd
fea681da
MK
108is not a socket.
109.TP
110.B EOPNOTSUPP
111The socket is not of a type that supports the
884dda7b 112.BR listen ()
fea681da
MK
113operation.
114.SH "CONFORMING TO"
97c1eac8
MK
1154.4BSD, POSIX.1-2001.
116The
884dda7b 117.BR listen ()
c13182ef 118function call first appeared in 4.2BSD.
fea681da 119.SH BUGS
c13182ef
MK
120If the socket is of type
121.BR AF_INET ,
fea681da
MK
122and the
123.I backlog
124argument is greater
c13182ef
MK
125than the constant
126.B SOMAXCONN
fea681da 127(128 in Linux 2.0 & 2.2), it is silently truncated
c13182ef
MK
128to
129.BR SOMAXCONN .
884dda7b
MK
130.\" The following is now rather historic information (MTK, Jun 05)
131.\" Don't rely on this value in portable applications since BSD
132.\" (and some BSD-derived systems) limit the backlog to 5.
fea681da
MK
133.SH "SEE ALSO"
134.BR accept (2),
884dda7b 135.BR bind (2),
fea681da
MK
136.BR connect (2),
137.BR socket (2)