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.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
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.
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
33 .\" $Id: listen.2,v 1.4 2001/05/19 02:09:20 hanataka Exp $
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>
42 .\" Japanese Version Copyright (c) 1998 Shinya HANATAKA, Takeshi Hakamada
43 .\" all rights reserved.
44 .\" Translated 1998-04-06,Shinya HANATAKA <shinya@abyss.rim.or.jp>
45 .\" and Takeshi Hakamada <hakamada@nsg.sgi.com>
46 .\" Modified 2000-01-13, Kentaro Shirakata <argrath@yo.rim.or.jp>
47 .\" Modified 2001-05-19, Shinya HANATAKA <shinya@abyss.rim.or.jp>
48 .\" Updated 2007-07-04, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.58
49 .\" Updated 2008-02-10, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.77
51 .\"WORD: socket ¥½¥±¥Ã¥È
54 .\"WORD: descriptor ¥Ç¥£¥¹¥¯¥ê¥×¥¿¡¼
56 .TH LISTEN 2 2008-11-20 "Linux" "Linux Programmer's Manual"
59 .\"O listen \- listen for connections on a socket
60 listen \- ¥½¥±¥Ã¥È(socket)¾å¤ÎÀܳ¤òÂÔ¤Ä
64 .\"O .BR "#include <sys/types.h>" " /* See NOTES */"
65 .BR "#include <sys/types.h>" " /* ¡ÖÃí°Õ¡×»²¾È */"
67 .B #include <sys/socket.h>
69 .BI "int listen(int " sockfd ", int " backlog );
74 .\"O marks the socket referred to by
76 .\"O as a passive socket, that is, as a socket that will
77 .\"O be used to accept incoming connection requests using
82 ¤¬»²¾È¤¹¤ë¥½¥±¥Ã¥È¤òÀܳÂÔ¤Á¥½¥±¥Ã¥È (passive socket) ¤È¤·¤Æ°õ¤ò¤Ä¤±¤ë¡£
83 ÀܳÂÔ¤Á¥½¥±¥Ã¥È¤È¤Ï¡¢
85 ¤ò»È¤Ã¤ÆÅþÃ夷¤¿ÀܳÍ×µá¤ò¼õ¤±ÉÕ¤±¤ë¤Î¤Ë»ÈÍѤµ¤ì¤ë¥½¥±¥Ã¥È¤Ç¤¢¤ë¡£
89 .\"O argument is a file descriptor that refers to a socket of type
92 .\"O .BR SOCK_SEQPACKET .
98 ·¿¤Î¥½¥±¥Ã¥È¤ò»²¾È¤¹¤ë¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç¤¢¤ë¡£
102 .\"O argument defines the maximum length
103 .\"O to which the queue of pending connections for
106 .\"O If a connection request arrives when the queue is full, the client
107 .\"O may receive an error with an indication of
109 .\"O or, if the underlying protocol supports retransmission, the request may be
110 .\"O ignored so that a later reattempt at connection succeeds.
114 ¤Ë¤Ä¤¤¤Æ¤ÎÊÝαÃæ¤ÎÀܳ¤Î¥¥å¡¼¤ÎºÇÂçŤò»ØÄꤹ¤ë¡£
115 ¥¥å¡¼¤¬¤¤¤Ã¤Ñ¤¤¤Î¾õÂÖ¤ÇÀܳÍ׵᤬ÅþÃ夹¤ë¤È¡¢¥¯¥é¥¤¥¢¥ó¥È¤Ï
117 ¤È¤¤¤¦¥¨¥é¡¼¤ò¼õ¤±¼è¤ë¡£²¼°ÌÁؤΥץí¥È¥³¥ë¤¬ºÆÁ÷¿®¤ò¥µ¥Ý¡¼¥È
118 ¤·¤Æ¤¤¤ì¤Ð¡¢Í×µá¤Ï̵»ë¤µ¤ì¡¢¤³¤ì°Ê¹ß¤ÎÀܳÍ×µá¤ÎºÆÁ÷¿®¤¬À®¸ù¤¹¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
119 .\"O .SH "RETURN VALUE"
121 .\"O On success, zero is returned.
122 .\"O On error, \-1 is returned, and
124 .\"O is set appropriately.
125 À®¸ù»þ¤Ë¤Ï0¤òÊÖ¤¹¡£¥¨¥é¡¼»þ¤Ë¤Ï \-1¤òÊÖ¤·¡¢
132 .\"O Another socket is already listening on the same port.
135 Ê̤Υ½¥±¥Ã¥È¤¬´û¤ËƱ¤¸¥Ý¡¼¥È¤ò listen ¤·¤Æ¤¤¤ë¡£
140 .\"O is not a valid descriptor.
143 ¤Ï͸ú¤Ê¥Ç¥£¥¹¥¯¥ê¥×¥¿¡¼¤Ç¤Ï¤Ê¤¤¡£
148 .\"O is not a socket.
154 .\"O The socket is not of a type that supports the
159 ¤¬¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤ë·¿¤Ç¤Ï¤Ê¤¤¡£
160 .\"O .SH "CONFORMING TO"
162 .\"O 4.4BSD, POSIX.1-2001.
165 .\"O function call first appeared in 4.2BSD.
166 4.4BSD, POSIX.1-2001.
168 ´Ø¿ô¤Ï 4.2BSD¤Ç½é¤á¤Æ¼ÂÁõ¤µ¤ì¤¿¡£
171 .\"O To accept connections, the following steps are performed:
172 Àܳ¤ò¼õ¤±ÉÕ¤±¤ë¤Ë¤Ï¡¢°Ê²¼¤Î½èÍý¤¬¼Â¹Ô¤µ¤ì¤ë¡£
175 .\"O A socket is created with
178 ¤Ç¥½¥±¥Ã¥È¤òºîÀ®¤¹¤ë¡£
180 .\"O The socket is bound to a local address using
182 .\"O so that other sockets may be
183 .\"O .BR connect (2)ed
186 ¤ò»È¤Ã¤Æ¥½¥±¥Ã¥È¤Ë¥í¡¼¥«¥ë¥¢¥É¥ì¥¹¤ò³ä¤êÅö¤Æ¤Æ¡¢
187 ¾¤Î¥½¥±¥Ã¥È¤¬¤³¤Î¥½¥±¥Ã¥È¤Ë
191 .\"O A willingness to accept incoming connections and a queue limit for incoming
192 .\"O connections are specified with
195 ¤ò»È¤Ã¤Æ¡¢ÀܳÍ×µá¤ò¼õ¤±ÉÕ¤±¤ë°Õ»Ö¤ÈÀܳÍ×µá¤òÆþ¤ì¤ë¥¥å¡¼Ä¹¤ò»ØÄꤹ¤ë¡£
197 .\"O Connections are accepted with
200 ¤ò»È¤Ã¤ÆÀܳ¤ò¼õ¤±ÉÕ¤±¤ë¡£
203 .\"O POSIX.1-2001 does not require the inclusion of
204 .\"O .IR <sys/types.h> ,
205 .\"O and this header file is not required on Linux.
206 .\"O However, some historical (BSD) implementations required this header
207 .\"O file, and portable applications are probably wise to include it.
210 ¤Î¥¤¥ó¥¯¥ë¡¼¥É¤Ïɬ¿Ü¤È¤µ¤ì¤Æ¤ª¤é¤º¡¢
211 Linux ¤Ç¤Ï¤³¤Î¥Ø¥Ã¥À¥Õ¥¡¥¤¥ë¤ÏɬÍפǤϤʤ¤¡£
212 ¤·¤«¤·¡¢Îò»ËŪ¤Ë¤Ï¡¢¤¤¤¯¤Ä¤«¤Î¼ÂÁõ (BSD ·Ï) ¤Ç¤³¤Î¥Ø¥Ã¥À¥Õ¥¡¥¤¥ë¤¬
213 ɬÍפǤ¢¤ê¡¢°Ü¿¢À¤¬É¬Íפʥ¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤Ï¤³¤Î¥Õ¥¡¥¤¥ë¤ò
214 ¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë¤Î¤¬¸ÌÀ¤Ç¤¢¤í¤¦¡£
216 .\"O The behavior of the
218 .\"O argument on TCP sockets changed with Linux 2.2.
221 °ú¤¿ô¤Î¿¶¤ëÉñ¤¤¤Ï Linux 2.2 ¤ÇÊѹ¹¤µ¤ì¤¿¡£
222 .\"O Now it specifies the queue length for
224 .\"O established sockets waiting to be accepted,
225 .\"O instead of the number of incomplete connection requests.
226 .\"O The maximum length of the queue for incomplete sockets
227 .\"O can be set using
228 .\"O .IR /proc/sys/net/ipv4/tcp_max_syn_backlog .
229 ¸½ºß¤Ç¤Ï¤³¤Î°ú¤¿ô¤Ï¡¢
230 ¼õ¤±ÉÕ¤±¤é¤ì¤ë¤Î¤òÂԤäƤ¤¤ë¡¢
232 ³ÎΩ¤µ¤ì¤¿¥½¥±¥Ã¥È¤Î¥¥å¡¼¤ÎŤµ¤ò»ØÄꤹ¤ë¡£
233 °ÊÁ°¤ÏÉÔ´°Á´¤ÊÀܳÍ×µá¤Î¿ô¤Ç¤¢¤Ã¤¿¤¬¡¢¤³¤ì¤òÃÖ¤´¹¤¨¤¿¡£
234 ÉÔ´°Á´¤Ê¥½¥±¥Ã¥È¤Î¥¥å¡¼¤ÎºÇÂçŤÏ
235 .I /proc/sys/net/ipv4/tcp_max_syn_backlog
237 .\"O When syncookies are enabled there is no logical maximum
238 .\"O length and this setting is ignored.
241 .\"O for more information.
242 syncookie ¤¬Í¸ú¤Ë¤Ê¤Ã¤Æ¤¤¤ë¾ì¹ç¡¢
243 ÏÀÍýŪ¤ÊºÇÂçĹ¤Ï¸ºß¤»¤º¡¢¤³¤ÎÀßÄê¤Ï̵»ë¤µ¤ì¤ë¡£
247 .\"O argument is greater than the value in
248 .\"O .IR /proc/sys/net/core/somaxconn ,
249 .\"O then it is silently truncated to that value;
250 .\"O the default value in this file is 128.
251 .\"O In kernels before 2.4.25, this limit was a hard coded value,
253 .\"O with the value 128.
256 .I /proc/sys/net/core/somaxconn
257 ¤ÎÃͤè¤ê¤âÂ礤±¤ì¤Ð¡¢
259 ¤ÎÃͤϰÅÌۤΤ¦¤Á¤Ë¤³¤ÎÃͤËÀÚ¤êµÍ¤á¤é¤ì¤ë¡£
260 ¤³¤Î¥Õ¥¡¥¤¥ë¤Î¥Ç¥Õ¥©¥ë¥ÈÃÍ¤Ï 128 ¤Ç¤¢¤ë¡£
261 ¥Ð¡¼¥¸¥ç¥ó 2.4.5 °ÊÁ°¤Î¥«¡¼¥Í¥ë¤Ç¤Ï¡¢¤³¤Î¾å¸ÂÃͤÏ
262 ¥³¡¼¥ÉËä¤á¹þ¤ß¤Î¸ÇÄêÃÍ
264 ¤Ç¤¢¤ê¡¢¤½¤ÎÃÍ¤Ï 128 ¤Ç¤¢¤Ã¤¿¡£
265 .\"O .\" The following is now rather historic information (MTK, Jun 05)
266 .\"O .\" Don't rely on this value in portable applications since BSD
267 .\"O .\" (and some BSD-derived systems) limit the backlog to 5.
268 .\" °Ê²¼¤Ï¡¢º£¤Ç¤Ï¸Å¤¤¾ðÊó¤Ç¤¢¤ë¡£(MTK, Jun 05)
269 .\" BSD (¤È¡¢¤¤¤¯¤Ä¤«¤Î BSD ¤«¤éÇÉÀ¸¤·¤¿¥·¥¹¥Æ¥à)¤Ç¤Ï backlog ¤ò 5 ¤Ë
270 .\" À©¸Â¤·¤Æ¤¤¤ë¤Î¤Ç¡¢°Ü¿¢À¤ò¹Íθ¤·¤¿¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤Ï
271 .\" ¤³¤ÎÃÍ (SOMAXCONN) ¤ËÍê¤Ã¤Æ¤Ï¤¤¤±¤Ê¤¤¡£