OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / LDP_man-pages / draft / man2 / listen.2
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.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
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.
20 .\"
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
31 .\" SUCH DAMAGE.
32 .\"
33 .\"     $Id: listen.2,v 1.4 2001/05/19 02:09:20 hanataka Exp $
34 .\"
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>
41 .\"
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
50 .\"
51 .\"WORD:        socket                  ¥½¥±¥Ã¥È
52 .\"WORD:        listen                  ´Æ»ë
53 .\"WORD:        queue                   ¥­¥å¡¼
54 .\"WORD:        descriptor              ¥Ç¥£¥¹¥¯¥ê¥×¥¿¡¼
55 .\"
56 .TH LISTEN 2 2008-11-20 "Linux" "Linux Programmer's Manual"
57 .\"O .SH NAME
58 .SH Ì¾Á°
59 .\"O listen \- listen for connections on a socket
60 listen \- ¥½¥±¥Ã¥È(socket)¾å¤ÎÀܳ¤òÂÔ¤Ä
61 .\"O .SH SYNOPSIS
62 .SH ½ñ¼°
63 .nf
64 .\"O .BR "#include <sys/types.h>" "          /* See NOTES */"
65 .BR "#include <sys/types.h>" "          /* ¡ÖÃí°Õ¡×»²¾È */"
66 .br
67 .B #include <sys/socket.h>
68 .sp
69 .BI "int listen(int " sockfd ", int " backlog );
70 .fi
71 .\"O .SH DESCRIPTION
72 .SH ÀâÌÀ
73 .\"O .BR listen ()
74 .\"O marks the socket referred to by
75 .\"O .I sockfd
76 .\"O as a passive socket, that is, as a socket that will
77 .\"O be used to accept incoming connection requests using
78 .\"O .BR accept (2).
79 .BR listen ()
80 ¤Ï
81 .I sockfd
82 ¤¬»²¾È¤¹¤ë¥½¥±¥Ã¥È¤òÀܳÂÔ¤Á¥½¥±¥Ã¥È (passive socket) ¤È¤·¤Æ°õ¤ò¤Ä¤±¤ë¡£
83 ÀܳÂÔ¤Á¥½¥±¥Ã¥È¤È¤Ï¡¢
84 .BR accept (2)
85 ¤ò»È¤Ã¤ÆÅþÃ夷¤¿ÀܳÍ×µá¤ò¼õ¤±ÉÕ¤±¤ë¤Î¤Ë»ÈÍѤµ¤ì¤ë¥½¥±¥Ã¥È¤Ç¤¢¤ë¡£
86
87 .\"O The
88 .\"O .I sockfd
89 .\"O argument is a file descriptor that refers to a socket of type
90 .\"O .B SOCK_STREAM
91 .\"O or
92 .\"O .BR SOCK_SEQPACKET .
93 .I sockfd
94 °ú¤­¿ô¤Ï¡¢
95 .B SOCK_STREAM
96 ·¿¤«
97 .B SOCK_SEQPACKET
98 ·¿¤Î¥½¥±¥Ã¥È¤ò»²¾È¤¹¤ë¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç¤¢¤ë¡£
99
100 .\"O The
101 .\"O .I backlog
102 .\"O argument defines the maximum length
103 .\"O to which the queue of pending connections for
104 .\"O .I sockfd
105 .\"O may grow.
106 .\"O If a connection request arrives when the queue is full, the client
107 .\"O may receive an error with an indication of
108 .\"O .B ECONNREFUSED
109 .\"O or, if the underlying protocol supports retransmission, the request may be
110 .\"O ignored so that a later reattempt at connection succeeds.
111 .I backlog
112 °ú¤­¿ô¤Ï¡¢
113 .I sockfd
114 ¤Ë¤Ä¤¤¤Æ¤ÎÊÝαÃæ¤ÎÀܳ¤Î¥­¥å¡¼¤ÎºÇÂçŤò»ØÄꤹ¤ë¡£
115 ¥­¥å¡¼¤¬¤¤¤Ã¤Ñ¤¤¤Î¾õÂÖ¤ÇÀܳÍ׵᤬ÅþÃ夹¤ë¤È¡¢¥¯¥é¥¤¥¢¥ó¥È¤Ï
116 .B ECONNREFUSED
117 ¤È¤¤¤¦¥¨¥é¡¼¤ò¼õ¤±¼è¤ë¡£²¼°ÌÁؤΥץí¥È¥³¥ë¤¬ºÆÁ÷¿®¤ò¥µ¥Ý¡¼¥È
118 ¤·¤Æ¤¤¤ì¤Ð¡¢Í×µá¤Ï̵»ë¤µ¤ì¡¢¤³¤ì°Ê¹ß¤ÎÀܳÍ×µá¤ÎºÆÁ÷¿®¤¬À®¸ù¤¹¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
119 .\"O .SH "RETURN VALUE"
120 .SH ÊÖ¤êÃÍ
121 .\"O On success, zero is returned.
122 .\"O On error, \-1 is returned, and
123 .\"O .I errno
124 .\"O is set appropriately.
125 À®¸ù»þ¤Ë¤Ï0¤òÊÖ¤¹¡£¥¨¥é¡¼»þ¤Ë¤Ï \-1¤òÊÖ¤·¡¢
126 .I errno
127 ¤òŬÀÚ¤ËÀßÄꤹ¤ë¡£
128 .\"O .SH ERRORS
129 .SH ¥¨¥é¡¼
130 .\"O .TP
131 .\"O .B EADDRINUSE
132 .\"O Another socket is already listening on the same port.
133 .TP
134 .B EADDRINUSE
135 Ê̤Υ½¥±¥Ã¥È¤¬´û¤ËƱ¤¸¥Ý¡¼¥È¤ò listen ¤·¤Æ¤¤¤ë¡£
136 .TP
137 .B EBADF
138 .\"O The argument
139 .\"O .I sockfd
140 .\"O is not a valid descriptor.
141 °ú¤­¿ô
142 .I sockfd
143 ¤ÏÍ­¸ú¤Ê¥Ç¥£¥¹¥¯¥ê¥×¥¿¡¼¤Ç¤Ï¤Ê¤¤¡£
144 .TP
145 .B ENOTSOCK
146 .\"O The argument
147 .\"O .I sockfd
148 .\"O is not a socket.
149 °ú¤­¿ô
150 .I sockfd
151 ¤Ï¥½¥±¥Ã¥È¤Ç¤Ï¤Ê¤¤¡£
152 .TP
153 .B EOPNOTSUPP
154 .\"O The socket is not of a type that supports the
155 .\"O .BR listen ()
156 .\"O operation.
157 ¥½¥±¥Ã¥È¤Ï
158 .BR listen ()
159 ¤¬¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤ë·¿¤Ç¤Ï¤Ê¤¤¡£
160 .\"O .SH "CONFORMING TO"
161 .SH ½àµò
162 .\"O 4.4BSD, POSIX.1-2001.
163 .\"O The
164 .\"O .B listen
165 .\"O function call first appeared in 4.2BSD.
166 4.4BSD, POSIX.1-2001.
167 .BR listen ()
168 ´Ø¿ô¤Ï 4.2BSD¤Ç½é¤á¤Æ¼ÂÁõ¤µ¤ì¤¿¡£
169 .\"O .SH NOTES
170 .SH Ãí°Õ
171 .\"O To accept connections, the following steps are performed:
172 Àܳ¤ò¼õ¤±ÉÕ¤±¤ë¤Ë¤Ï¡¢°Ê²¼¤Î½èÍý¤¬¼Â¹Ô¤µ¤ì¤ë¡£
173 .RS 4
174 .IP 1. 4
175 .\"O A socket is created with
176 .\"O .BR socket (2).
177 .BR socket (2)
178 ¤Ç¥½¥±¥Ã¥È¤òºîÀ®¤¹¤ë¡£
179 .IP 2.
180 .\"O The socket is bound to a local address using
181 .\"O .BR bind (2),
182 .\"O so that other sockets may be
183 .\"O .BR connect (2)ed
184 .\"O to it.
185 .BR bind (2)
186 ¤ò»È¤Ã¤Æ¥½¥±¥Ã¥È¤Ë¥í¡¼¥«¥ë¥¢¥É¥ì¥¹¤ò³ä¤êÅö¤Æ¤Æ¡¢
187 ¾¤Î¥½¥±¥Ã¥È¤¬¤³¤Î¥½¥±¥Ã¥È¤Ë
188 .BR connect (2)
189 ¤Ç¤­¤ë¤è¤¦¤Ë¤¹¤ë¡£
190 .IP 3.
191 .\"O A willingness to accept incoming connections and a queue limit for incoming
192 .\"O connections are specified with
193 .\"O .BR listen ().
194 .BR listen ()
195 ¤ò»È¤Ã¤Æ¡¢ÀܳÍ×µá¤ò¼õ¤±ÉÕ¤±¤ë°Õ»Ö¤ÈÀܳÍ×µá¤òÆþ¤ì¤ë¥­¥å¡¼Ä¹¤ò»ØÄꤹ¤ë¡£
196 .IP 4.
197 .\"O Connections are accepted with
198 .\"O .BR accept (2).
199 .BR accept (2)
200 ¤ò»È¤Ã¤ÆÀܳ¤ò¼õ¤±ÉÕ¤±¤ë¡£
201 .RE
202 .PP
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.
208 POSIX.1-2001 ¤Ç¤Ï
209 .I <sys/types.h>
210 ¤Î¥¤¥ó¥¯¥ë¡¼¥É¤Ïɬ¿Ü¤È¤µ¤ì¤Æ¤ª¤é¤º¡¢
211 Linux ¤Ç¤Ï¤³¤Î¥Ø¥Ã¥À¥Õ¥¡¥¤¥ë¤ÏɬÍפǤϤʤ¤¡£
212 ¤·¤«¤·¡¢Îò»ËŪ¤Ë¤Ï¡¢¤¤¤¯¤Ä¤«¤Î¼ÂÁõ (BSD ·Ï) ¤Ç¤³¤Î¥Ø¥Ã¥À¥Õ¥¡¥¤¥ë¤¬
213 ɬÍפǤ¢¤ê¡¢°Ü¿¢À­¤¬É¬Íפʥ¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤Ï¤³¤Î¥Õ¥¡¥¤¥ë¤ò
214 ¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë¤Î¤¬¸­ÌÀ¤Ç¤¢¤í¤¦¡£
215
216 .\"O The behavior of the
217 .\"O .I backlog
218 .\"O argument on TCP sockets changed with Linux 2.2.
219 TCP ¥½¥±¥Ã¥È¤Ç¤Î
220 .I backlog
221 °ú¤­¿ô¤Î¿¶¤ëÉñ¤¤¤Ï Linux 2.2 ¤ÇÊѹ¹¤µ¤ì¤¿¡£
222 .\"O Now it specifies the queue length for
223 .\"O .I completely
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 ¼õ¤±ÉÕ¤±¤é¤ì¤ë¤Î¤òÂԤäƤ¤¤ë¡¢
231 .I ´°Á´¤Ë
232 ³ÎΩ¤µ¤ì¤¿¥½¥±¥Ã¥È¤Î¥­¥å¡¼¤ÎŤµ¤ò»ØÄꤹ¤ë¡£
233 °ÊÁ°¤ÏÉÔ´°Á´¤ÊÀܳÍ×µá¤Î¿ô¤Ç¤¢¤Ã¤¿¤¬¡¢¤³¤ì¤òÃÖ¤­´¹¤¨¤¿¡£
234 ÉÔ´°Á´¤Ê¥½¥±¥Ã¥È¤Î¥­¥å¡¼¤ÎºÇÂçŤÏ
235 .I /proc/sys/net/ipv4/tcp_max_syn_backlog
236 ¤òÍѤ¤¤ÆÀßÄê¤Ç¤­¤ë¡£
237 .\"O When syncookies are enabled there is no logical maximum
238 .\"O  length and this setting is ignored.
239 .\"O See
240 .\"O .BR tcp (7)
241 .\"O for more information.
242 syncookie ¤¬Í­¸ú¤Ë¤Ê¤Ã¤Æ¤¤¤ë¾ì¹ç¡¢
243 ÏÀÍýŪ¤ÊºÇÂçĹ¤Ï¸ºß¤»¤º¡¢¤³¤ÎÀßÄê¤Ï̵»ë¤µ¤ì¤ë¡£
244
245 .\"O If the
246 .\"O .I backlog
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,
252 .\"O .BR SOMAXCONN ,
253 .\"O with the value 128.
254 .I backlog
255 °ú¤­¿ô¤¬
256 .I /proc/sys/net/core/somaxconn
257 ¤ÎÃͤè¤ê¤âÂ礭¤±¤ì¤Ð¡¢
258 .I backlog
259 ¤ÎÃͤϰÅÌۤΤ¦¤Á¤Ë¤³¤ÎÃͤËÀÚ¤êµÍ¤á¤é¤ì¤ë¡£
260 ¤³¤Î¥Õ¥¡¥¤¥ë¤Î¥Ç¥Õ¥©¥ë¥ÈÃͤϠ128 ¤Ç¤¢¤ë¡£
261 ¥Ð¡¼¥¸¥ç¥ó 2.4.5 °ÊÁ°¤Î¥«¡¼¥Í¥ë¤Ç¤Ï¡¢¤³¤Î¾å¸ÂÃͤÏ
262 ¥³¡¼¥ÉËä¤á¹þ¤ß¤Î¸ÇÄêÃÍ
263 .B SOMAXCONN
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) ¤ËÍê¤Ã¤Æ¤Ï¤¤¤±¤Ê¤¤¡£
272 .\"O .SH EXAMPLE
273 .SH Îã
274 .\"O See
275 .\"O .BR bind (2).
276 .BR bind (2)
277 »²¾È¡£
278 .\"O .SH "SEE ALSO"
279 .SH ´ØÏ¢¹àÌÜ
280 .BR accept (2),
281 .BR bind (2),
282 .BR connect (2),
283 .BR socket (2),
284 .BR socket (7)