OSDN Git Service

(split) LDP: Release pages for LDP v3.39.
[linuxjm/LDP_man-pages.git] / release / 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.6 1999/05/18 14:10:32 freitag 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 .\"
43 .\"*******************************************************************
44 .\"
45 .\" This file was generated with po4a. Translate the source file.
46 .\"
47 .\"*******************************************************************
48 .TH LISTEN 2 2008\-11\-20 Linux "Linux Programmer's Manual"
49 .SH 名前
50 listen \- ソケット(socket)上の接続を待つ
51 .SH 書式
52 .nf
53 \fB#include <sys/types.h>\fP          /* 「注意」参照 */
54 .br
55 \fB#include <sys/socket.h>\fP
56 .sp
57 \fBint listen(int \fP\fIsockfd\fP\fB, int \fP\fIbacklog\fP\fB);\fP
58 .fi
59 .SH 説明
60 \fBlisten\fP()  は \fIsockfd\fP が参照するソケットを接続待ちソケット (passive socket) として印をつける。
61 接続待ちソケットとは、 \fBaccept\fP(2)  を使って到着した接続要求を受け付けるのに使用されるソケットである。
62
63 \fIsockfd\fP 引き数は、 \fBSOCK_STREAM\fP 型か \fBSOCK_SEQPACKET\fP
64 型のソケットを参照するファイルディスクリプタである。
65
66 \fIbacklog\fP 引き数は、 \fIsockfd\fP についての保留中の接続のキューの最大長を指定する。
67 キューがいっぱいの状態で接続要求が到着すると、クライアントは \fBECONNREFUSED\fP
68 というエラーを受け取る。下位層のプロトコルが再送信をサポート していれば、要求は無視され、これ以降の接続要求の再送信が成功するかもしれない。
69 .SH 返り値
70 成功した場合にはゼロが返される。エラー時には \-1 が返され、 \fIerrno\fP が適切に設定される。
71 .SH エラー
72 .TP 
73 \fBEADDRINUSE\fP
74 別のソケットが既に同じポートを listen している。
75 .TP 
76 \fBEBADF\fP
77 引き数 \fIsockfd\fP は有効なディスクリプターでない。
78 .TP 
79 \fBENOTSOCK\fP
80 引き数 \fIsockfd\fP はソケットではない。
81 .TP 
82 \fBEOPNOTSUPP\fP
83 ソケットは \fBlisten\fP()  がサポートしている型ではない。
84 .SH 準拠
85 4.4BSD, POSIX.1\-2001.  \fBlisten\fP()  関数は 4.2BSDで初めて実装された。
86 .SH 注意
87 接続を受け付けるには、以下の処理が実行される。
88 .RS 4
89 .IP 1. 4
90 \fBsocket\fP(2)  でソケットを作成する。
91 .IP 2.
92 \fBbind\fP(2)  を使ってソケットにローカルアドレスを割り当てて、 他のソケットがこのソケットに \fBconnect\fP(2)  できるようにする。
93 .IP 3.
94 \fBlisten\fP()  を使って、接続要求を受け付ける意志と接続要求を入れるキュー長を指定する。
95 .IP 4.
96 \fBaccept\fP(2)  を使って接続を受け付ける。
97 .RE
98 .PP
99 POSIX.1\-2001 では \fI<sys/types.h>\fP のインクルードは必須とされておらず、 Linux
100 ではこのヘッダファイルは必要ではない。 しかし、歴史的には、いくつかの実装 (BSD 系) でこのヘッダファイルが
101 必要であり、移植性が必要なアプリケーションではこのファイルを インクルードするのが賢明であろう。
102
103 TCP ソケットでの \fIbacklog\fP 引き数の振る舞いは Linux 2.2 で変更された。 現在ではこの引き数は、
104 受け付けられるのを待っている、 \fI完全に\fP 確立されたソケットのキューの長さを指定する。 以前は不完全な接続要求の数であったが、これを置き換えた。
105 不完全なソケットのキューの最大長は \fI/proc/sys/net/ipv4/tcp_max_syn_backlog\fP を用いて設定できる。
106 syncookie が有効になっている場合、 論理的な最大長は存在せず、この設定は無視される。
107
108 .\" The following is now rather historic information (MTK, Jun 05)
109 .\" Don't rely on this value in portable applications since BSD
110 .\" (and some BSD-derived systems) limit the backlog to 5.
111 \fIbacklog\fP 引き数が \fI/proc/sys/net/core/somaxconn\fP の値よりも大きければ、 \fIbacklog\fP
112 の値は暗黙のうちにこの値に切り詰められる。 このファイルのデフォルト値は 128 である。 バージョン 2.4.5 以前のカーネルでは、この上限値は
113 コード埋め込みの固定値 \fBSOMAXCONN\fP であり、その値は 128 であった。
114 .SH 例
115 \fBbind\fP(2)  参照。
116 .SH 関連項目
117 \fBaccept\fP(2), \fBbind\fP(2), \fBconnect\fP(2), \fBsocket\fP(2), \fBsocket\fP(7)