]>
Commit | Line | Data |
---|---|---|
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 |
43 | listen \- 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 |
53 | To accept connections, a socket is first created with | |
54 | .BR socket (2), | |
55 | a willingness to accept incoming connections and a queue limit for incoming | |
56 | connections are specified with | |
884dda7b | 57 | .BR listen (), |
fea681da MK |
58 | and then the connections are |
59 | accepted with | |
60 | .BR accept (2). | |
61 | The | |
884dda7b | 62 | .BR listen () |
fea681da MK |
63 | call applies only to sockets of type |
64 | .B SOCK_STREAM | |
65 | or | |
66 | .BR SOCK_SEQPACKET . | |
67 | .PP | |
68 | The | |
69 | .I backlog | |
70 | parameter defines the maximum length the queue of pending connections may | |
c13182ef MK |
71 | grow to. |
72 | If a connection request arrives with the queue full the client | |
fea681da MK |
73 | may receive an error with an indication of |
74 | .B ECONNREFUSED | |
75 | or, if the underlying protocol supports retransmission, the request may be | |
76 | ignored so that retries succeed. | |
fea681da | 77 | .SH "RETURN VALUE" |
c13182ef MK |
78 | On success, zero is returned. |
79 | On error, \-1 is returned, and | |
fea681da MK |
80 | .I errno |
81 | is set appropriately. | |
82 | .SH ERRORS | |
83 | .TP | |
84 | .B EADDRINUSE | |
85 | Another socket is already listening on the same port. | |
86 | .TP | |
87 | .B EBADF | |
88 | The argument | |
3e6b03a0 | 89 | .I sockfd |
fea681da MK |
90 | is not a valid descriptor. |
91 | .TP | |
92 | .B ENOTSOCK | |
93 | The argument | |
3e6b03a0 | 94 | .I sockfd |
fea681da MK |
95 | is not a socket. |
96 | .TP | |
97 | .B EOPNOTSUPP | |
98 | The socket is not of a type that supports the | |
884dda7b | 99 | .BR listen () |
fea681da MK |
100 | operation. |
101 | .SH "CONFORMING TO" | |
97c1eac8 MK |
102 | 4.4BSD, POSIX.1-2001. |
103 | The | |
884dda7b | 104 | .BR listen () |
c13182ef | 105 | function call first appeared in 4.2BSD. |
a1d5f77c | 106 | .SH NOTES |
53a6b01d MK |
107 | POSIX.1-2001 does not require the inclusion of |
108 | .IR <sys/types.h> , | |
109 | and this header file is not required on Linux. | |
110 | However, some historical (BSD) implementations required this header | |
111 | file, and portable applications are probably wise to include it. | |
112 | ||
d9bfdb9c | 113 | The behavior of the |
a1d5f77c MK |
114 | .I backlog |
115 | parameter on TCP sockets changed with Linux 2.2. | |
116 | Now it specifies the queue length for | |
117 | .I completely | |
5edee420 MK |
118 | established sockets waiting to be accepted, |
119 | instead of the number of incomplete connection requests. | |
a1d5f77c MK |
120 | The maximum length of the queue for incomplete sockets |
121 | can be set using the | |
66ee0c7e | 122 | .I tcp_max_syn_backlog |
a1d5f77c MK |
123 | sysctl. |
124 | When syncookies are enabled there is no logical maximum | |
125 | length and this sysctl setting is ignored. | |
126 | See | |
127 | .BR tcp (7) | |
128 | for more information. | |
5edee420 MK |
129 | |
130 | If the | |
fea681da | 131 | .I backlog |
5edee420 MK |
132 | argument is greater than the value in |
133 | .IR /proc/sys/net/somaxconn , | |
134 | then it is silently truncated to that value; | |
135 | the default value in this file is 128. | |
136 | In kernels before 2.4.25, this limit was a hard coded value, | |
137 | .BR SOMAXCONN , | |
138 | with 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 |
143 | See | |
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) |