MQ_RECEIVE(3) | Linux Programmer's Manual | MQ_RECEIVE(3) |
mq_receive, mq_timedreceive - メッセージキューからメッセージを受信する
#include <mqueue.h>
ssize_t mq_receive(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned int *msg_prio);
#include <time.h> #include <mqueue.h>
ssize_t mq_timedreceive(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned int *msg_prio, const struct timespec *abs_timeout);
-lrt でリンクする。
mq_timedreceive():
mq_receive() は、メッセージキュー記述子 mqdes で参照されるメッセージキューから最も高い優先度を持つ 最も古いメッセージを削除し、そのメッセージを msg_ptr が指すバッファーに格納する。 msg_len 引数は、 msg_ptr が指すバッファーの大きさを示す。この値はキューの mq_msgsize 属性以上でなければならない (mq_getattr(3) 参照)。 msg_prio が NULL 以外の場合、 msg_prio が指すバッファーに受信したメッセージの優先度が格納される。
キューが空の場合、デフォルトでは、 mq_receive() は、新しいメッセージが届くか、関数呼び出しがシグナルハンドラーにより 中断されるまで、停止 (block) する。 メッセージキュー記述 (message queue description) で O_NONBLOCK フラグが有効になっている場合は、 mq_receive() はエラー EAGAIN ですぐに失敗する。
mq_timedreceive() behaves just like mq_receive(), except that if the queue is empty and the O_NONBLOCK flag is not enabled for the message queue description, then abs_timeout points to a structure which specifies how long the call will block. This value is an absolute timeout in seconds and nanoseconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC), specified in the following structure:
struct timespec { time_t tv_sec; /* 秒 */ long tv_nsec; /* ナノ秒 */ };
メッセージがキューになく、関数呼び出し時にすでにタイムアウト時刻が 過ぎている場合、 mq_timedreceive() はすぐに返る。
成功すると、 mq_receive() と mq_timedreceive() は受信したメッセージのバイト数を返す。 エラーの場合、-1 を返し、 errno にエラーを示す値を設定する。
この節で使用されている用語の説明については、 attributes(7) を参照。
インターフェース | 属性 | 値 |
mq_receive(), mq_timedreceive() | Thread safety | MT-Safe |
POSIX.1-2001, POSIX.1-2008.
Linux では、 mq_timedreceive() はシステムコールである。 mq_receive() はライブラリ関数で、 mq_timedreceive() システムコールを用いて実装されている。
mq_close(3), mq_getattr(3), mq_notify(3), mq_open(3), mq_send(3), mq_unlink(3), mq_overview(7), time(7)
この man ページは Linux man-pages プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は https://www.kernel.org/doc/man-pages/ に書かれている。
2020-08-13 | Linux |