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