OSDN Git Service

1a9768dae4bb28e4daa044caa079bbd961df3829
[linuxjm/LDP_man-pages.git] / release / man3 / mq_receive.3
1 '\" t
2 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\"
4 .\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
5 .\"
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein.  The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\"
26 .\" Japanese Version Copyright (c) 2006 Akihiro MOTOKI all rights reserved.
27 .\" Translated 2006-04-23, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
28 .\" Updated 2008-11-09, Akihiro MOTOKI, LDP v3.13
29 .\"
30 .TH MQ_RECEIVE 3 2010-09-20 "Linux" "Linux Programmer's Manual"
31 .SH 名前
32 mq_receive, mq_timedreceive \- メッセージキューからメッセージを受信する
33 .SH 書式
34 .nf
35 .B #include <mqueue.h>
36 .sp
37 .BI "ssize_t mq_receive(mqd_t " mqdes ", char *" msg_ptr ,
38 .BI "                   size_t " msg_len ", unsigned *" msg_prio );
39 .sp
40 .B #include <time.h>
41 .B #include <mqueue.h>
42 .sp
43 .BI "ssize_t mq_timedreceive(mqd_t " mqdes ", char *" msg_ptr ,
44 .BI "                   size_t " msg_len ", unsigned *" msg_prio ,
45 .BI "                   const struct timespec *" abs_timeout );
46 .fi
47 .sp
48 \fI\-lrt\fP でリンクする。
49 .sp
50 .ad l
51 .in -4n
52 glibc 向けの機能検査マクロの要件
53 .RB ( feature_test_macros (7)
54 参照):
55 .in
56 .sp
57 .BR mq_timedreceive ():
58 .RS 4
59 _XOPEN_SOURCE\ >=\ 600 || _POSIX_C_SOURCE\ >=\ 200112L
60 .RE
61 .ad
62 .SH 説明
63 .BR mq_receive ()
64 は、記述子
65 .I mqdes
66 で参照されるメッセージキューから最も高い優先度を持つ
67 最も古いメッセージを削除し、そのメッセージを
68 .I msg_ptr
69 が指すバッファに格納する。
70 .I msg_len
71 引き数は、
72 .I msg_ptr
73 が指すバッファの大きさを示す。この値はキューの
74 .I mq_msgsize
75 属性よりも大きくなければならない
76 .RB ( mq_getattr (3)
77 参照)。
78 .I prio
79 が NULL 以外の場合、
80 .I prio
81 が指すバッファに受信したメッセージの優先度が格納される。
82
83 キューが空の場合、デフォルトでは、
84 .BR mq_receive ()
85 は、新しいメッセージが届くか、関数呼び出しがシグナルハンドラにより
86 中断されるまで、停止 (block) する。
87 メッセージキュー記述 (message queue description) で
88 .B O_NONBLOCK
89 フラグが有効になっている場合は、
90 .BR mq_receive ()
91 はエラー
92 .B EAGAIN
93 ですぐに失敗する。
94
95 .BR mq_timedreceive ()
96
97 .BR mq_receive ()
98 と全く同じ動作をするが、
99 メッセージキューが空で、メッセージキュー記述で
100 .B O_NONBLOCK
101 フラグが有効になっていない場合に、この呼び出しが停止する時間の上限を
102 .I abs_timeout
103 が指す構造体で指定する点が異なる。この上限は、タイムアウトの時刻を、
104 時刻紀元 (Epoch; 1970-01-01 00:00:00 +0000 (UTC)) からの経過時間
105 (秒とナノ秒の組) で指定する。タイムアウト時刻は以下の構造体で指定する:
106 .sp
107 .in +4n
108 .nf
109 struct timespec {
110     time_t tv_sec;        /* 秒 */
111     long   tv_nsec;       /* ナノ秒 */
112 };
113
114 .fi
115 .in
116 メッセージがキューになく、関数呼び出し時にすでにタイムアウト時刻が
117 過ぎている場合、
118 .BR mq_timedreceive ()
119 はすぐに返る。
120 .SH 返り値
121 成功すると、
122 .BR mq_receive ()
123
124 .BR mq_timedreceive ()
125 は受信したメッセージのバイト数を返す。
126 エラーの場合、\-1 を返し、
127 .I errno
128 にエラーを示す値を設定する。
129 .SH エラー
130 .TP
131 .B EAGAIN
132 キューが空で、かつ
133 .I mqdes
134 で参照されるメッセージキュー記述で
135 .B O_NONBLOCK
136 フラグがセットされていた。
137 .TP
138 .B EBADF
139 .I mqdes
140 で指定された記述子が不正である。
141 .TP
142 .B EINTR
143 関数呼び出しがシグナルハンドラにより中断された。
144 .BR signal (7)
145 参照。
146 .TP
147 .B EINVAL
148 関数呼び出しは停止するはずであったが、
149 .I abs_timeout
150 が不正であった。
151 .I abs_timeout
152 が不正とは、
153 .I tv_sec
154 が 0 未満、もしくは
155 .I tv_nsec
156 が 0 未満か 1,000,000,000 より大きい、ということである。
157 .TP
158 .B EMSGSIZE
159 .I msg_len
160 がメッセージキューの
161 .I mq_msgsize
162 属性よりも小さかった。
163 .TP
164 .B ETIMEDOUT
165 メッセージが転送される前に関数呼び出しがタイムアウトした。
166 .SH 準拠
167 POSIX.1-2001.
168 .SH 注意
169 Linux では、
170 .BR mq_timedreceive ()
171 はシステムコールである。
172 .BR mq_receive ()
173 はライブラリ関数で、
174 .BR mq_timedreceive ()
175 システムコールを用いて実装されている。
176 .SH 関連項目
177 .BR mq_close (3),
178 .BR mq_getattr (3),
179 .BR mq_notify (3),
180 .BR mq_open (3),
181 .BR mq_send (3),
182 .BR mq_unlink (3),
183 .BR mq_overview (7),
184 .BR time (7)