OSDN Git Service

(split) LDP: Update the version to 3.53 in PO files
[linuxjm/LDP_man-pages.git] / draft / man2 / sendmmsg.2
1 .\" Copyright (c) 2012 by Michael Kerrisk <mtk.manpages@gmail.com>
2 .\" with some material from a draft by
3 .\" Stephan Mueller <stephan.mueller@atsec.com>
4 .\" in turn based on Andi Kleen's recvmmsg.2 page.
5 .\"
6 .\" %%%LICENSE_START(VERBATIM)
7 .\" Permission is granted to make and distribute verbatim copies of this
8 .\" manual provided the copyright notice and this permission notice are
9 .\" preserved on all copies.
10 .\"
11 .\" Permission is granted to copy and distribute modified versions of this
12 .\" manual under the conditions for verbatim copying, provided that the
13 .\" entire resulting derived work is distributed under the terms of a
14 .\" permission notice identical to this one.
15 .\"
16 .\" Since the Linux kernel and libraries are constantly changing, this
17 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
18 .\" responsibility for errors or omissions, or for damages resulting from
19 .\" the use of the information contained herein.  The author(s) may not
20 .\" have taken the same level of care in the production of this manual,
21 .\" which is licensed free of charge, as they might when working
22 .\" professionally.
23 .\"
24 .\" Formatted or processed versions of this manual, if unaccompanied by
25 .\" the source, must acknowledge the copyright and authors of this work.
26 .\" %%%LICENSE_END
27 .\"
28 .\"*******************************************************************
29 .\"
30 .\" This file was generated with po4a. Translate the source file.
31 .\"
32 .\"*******************************************************************
33 .TH SENDMMSG 2 2012\-12\-16 Linux "Linux Programmer's Manual"
34 .SH 名前
35 sendmmsg \- 複数のメッセージをソケットへ送信する
36 .SH 書式
37 .nf
38 \fB#define _GNU_SOURCE\fP
39 \fB#include <sys/socket.h>\fP
40
41 \fBint sendmmsg(int \fP\fIsockfd\fP\fB, struct mmsghdr *\fP\fImsgvec\fP\fB, unsigned int \fP\fIvlen\fP\fB,\fP
42 \fB             unsigned int \fP\fIflags\fP\fB);\fP
43 .fi
44 .SH 説明
45 .\" See commit 228e548e602061b08ee8e8966f567c12aa079682
46 \fBsendmmsg\fP() システムコールは \fBsendmsg\fP(2) の拡張で、
47 このシステムコールを使うと一度の呼び出しでソケットに複数のメッセージを送信できる (アプリケーションによっては性能上のメリットがある)。
48
49 \fIsockfd\fP 引き数は、 データを送信するソケットのファイルディスクリプタである。
50
51 \fImsgvec\fP 引き数は \fImmsghdr\fP 構造体の配列である。 この配列の大きさは \fIvlen\fP で指定する。
52
53 \fImmsghdr\fP 構造体は \fI<sys/socket.h>\fP で次のように定義されている。
54
55 .in +4n
56 .nf
57 struct mmsghdr {
58     struct msghdr msg_hdr;  /* メッセージヘッダ */
59     unsigned int  msg_len;  /* 送信されたバイト数 */
60 };
61 .fi
62 .in
63 .PP
64 \fImsg_hdr\fP フィールドは、 \fBsendmsg\fP(2) で説明されている \fImsghdr\fP 構造体である。 \fImsg_len\fP
65 フィールドは \fImsg_hdr\fP から送信されたメッセージのバイト数を返すのに使用される。 この値は \fBsendmsg\fP(2)
66 をこのヘッダに対して呼び出した場合の返り値と同じである。
67
68 \fIflags\fP 引き数には複数のフラグを論理和 (OR) で指定できる。フラグは \fBsendmsg\fP(2) と同じである。
69
70 停止 (blocking) モードの \fBsendmmsg\fP() の呼び出しは、 \fIvlen\fP 個のメッセージが送信されるまで停止する。 非停止
71 (nonblocking) モードの呼び出しでは、 送信できるだけのメッセージ (最大で \fIvlen\fP 個) を送信し、 すぐに返る。
72
73 \fBsendmmsg\fP() が返った際には、 \fImsgvec\fP の送信が行われた要素の \fImsg_len\fP フィールドは、対応する
74 \fImsg_hdr\fP から送信されたバイト数が入っている。 呼び出しの返り値は、更新された \fImsgvec\fP の要素数である。
75 .SH 返り値
76 成功すると、 \fBsendmmsg\fP() は \fImsgvec\fP から送信されたメッセージ数を返す。 返り値が \fIvlen\fP よりも小さい場合、
77 呼び出した側では再度 \fBsendmmsg\fP を呼び出して残りのメッセージを送信することができる。
78
79 エラーの場合、 \-1 を返し、 \fIerrno\fP にエラーを示す値を設定する。
80 .SH エラー
81 .\" commit 728ffb86f10873aaf4abd26dde691ee40ae731fe
82 .\"     ... only return an error if no datagrams could be sent.
83 .\"     If less than the requested number of messages were sent, the application
84 .\"     must retry starting at the first failed one and if the problem is
85 .\"     persistent the error will be returned.
86 .\"
87 .\"     This matches the behaviour of other syscalls like read/write - it
88 .\"     is not an error if less than the requested number of elements are sent.
89 エラーは \fBsendmsg\fP(2) と同じである。 エラーが返されるのは、 データグラムが全く送信できなかった場合のみである。
90 .SH バージョン
91 \fBsendmmsg\fP() システムコールは Linux 3.0 で追加された。 glibc でのサポートはバージョン 2.14 で追加された。
92 .SH 準拠
93 \fBsendmmsg\fP() は Linux 固有である。
94 .SH 注意
95 .\" commit 98382f419f32d2c12d021943b87dea555677144b
96 .\"     net: Cap number of elements for sendmmsg
97 .\"
98 .\"     To limit the amount of time we can spend in sendmmsg, cap the
99 .\"     number of elements to UIO_MAXIOV (currently 1024).
100 .\"
101 .\"     For error handling an application using sendmmsg needs to retry at
102 .\"     the first unsent message, so capping is simpler and requires less
103 .\"     application logic than returning EINVAL.
104 \fIvlen\fP に指定できる値の最大値は \fBUIO_MAXIOV\fP (1024) である。
105 .SH 例
106 以下の例では、 \fBsendmmsg\fP() を使って、 一度のシステムコールで、 \fIonetwo\fP と \fIthree\fP を二つの別々の UDP
107 データグラムで送信する。 一つ目のデータグラムの内容は、二つのバッファから取得される。
108
109 .nf
110 #define _GNU_SOURCE
111 #include <netinet/ip.h>
112 #include <stdio.h>
113 #include <stdlib.h>
114 #include <string.h>
115 #include <sys/types.h>
116 #include <sys/socket.h>
117
118 int
119 main(void)
120 {
121     int sockfd;
122     struct sockaddr_in sa;
123     struct mmsghdr msg[2];
124     struct iovec msg1[2], msg2;
125     int retval;
126
127     sockfd = socket(AF_INET, SOCK_DGRAM, 0);
128     if (sockfd == \-1) {
129         perror("socket()");
130         exit(EXIT_FAILURE);
131     }
132
133     sa.sin_family = AF_INET;
134     sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
135     sa.sin_port = htons(1234);
136     if (connect(sockfd, (struct sockaddr *) &sa, sizeof(sa)) == \-1) {
137         perror("connect()");
138         exit(EXIT_FAILURE);
139     }
140
141     memset(msg1, 0, sizeof(msg1));
142     msg1[0].iov_base = "one";
143     msg1[0].iov_len = 3;
144     msg1[1].iov_base = "two";
145     msg1[1].iov_len = 3;
146
147     memset(&msg2, 0, sizeof(msg2));
148     msg2.iov_base = "three";
149     msg2.iov_len = 5;
150
151     memset(msg, 0, sizeof(msg));
152     msg[0].msg_hdr.msg_iov = msg1;
153     msg[0].msg_hdr.msg_iovlen = 2;
154
155     msg[1].msg_hdr.msg_iov = &msg2;
156     msg[1].msg_hdr.msg_iovlen = 1;
157
158     retval = sendmmsg(sockfd, msg, 2, 0);
159     if (retval == \-1)
160         perror("sendmmsg()");
161     else
162         printf("%d messages sent\en", retval);
163
164     exit(0);
165 }
166 .fi
167 .SH 関連項目
168 \fBrecvmmsg\fP(2), \fBsendmsg\fP(2), \fBsocket\fP(2), \fBsocket\fP(7)
169 .SH この文書について
170 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.53 の一部
171 である。プロジェクトの説明とバグ報告に関する情報は
172 http://www.kernel.org/doc/man\-pages/ に書かれている。