📄 mq_receive.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2003 The Open Group, All Rights Reserved --><title>mq_receive</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="mq_receive"></a> <a name="tag_03_386"></a><!-- mq_receive --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright © 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_386_01"></a>NAME</h4><blockquote>mq_receive, mq_timedreceive - receive a message from a message queue (<b>REALTIME</b>)</blockquote><h4><a name="tag_03_386_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><div class="box"><code><tt><sup>[<a href="javascript:open_code('MSG')">MSG</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> #include <<a href="../basedefs/mqueue.h.html">mqueue.h</a>><br><br> ssize_t mq_receive(mqd_t</tt> <i>mqdes</i><tt>, char *</tt><i>msg_ptr</i><tt>, size_t</tt> <i>msg_len</i><tt>,<br> unsigned *</tt><i>msg_prio</i><tt>); <img src="../images/opt-end.gif" alt="[Option End]"border="0"></tt></code></div><tt><br><br></tt> <div class="box"><code><tt><sup>[<a href="javascript:open_code('MSG TMO')">MSG TMO</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"><br> #include <<a href="../basedefs/mqueue.h.html">mqueue.h</a>><br> #include <<a href="../basedefs/time.h.html">time.h</a>><br> ssize_t mq_timedreceive(mqd_t</tt> <i>mqdes</i><tt>, char *restrict</tt> <i>msg_ptr</i><tt>,<br> size_t</tt> <i>msg_len</i><tt>, unsigned *restrict</tt> <i>msg_prio</i><tt>,<br> const struct timespec *restrict</tt> <i>abs_timeout</i><tt>); <img src="../images/opt-end.gif" alt="[Option End]" border="0"></tt></code></div><tt><br></tt></blockquote><h4><a name="tag_03_386_03"></a>DESCRIPTION</h4><blockquote><p>The <i>mq_receive</i>() function shall receive the oldest of the highest priority message(s) from the message queue specified by<i>mqdes</i>. If the size of the buffer in bytes, specified by the <i>msg_len</i> argument, is less than the <i>mq_msgsize</i>attribute of the message queue, the function shall fail and return an error. Otherwise, the selected message shall be removed fromthe queue and copied to the buffer pointed to by the <i>msg_ptr</i> argument.</p><p>If the value of <i>msg_len</i> is greater than {SSIZE_MAX}, the result is implementation-defined.</p><p>If the argument <i>msg_prio</i> is not NULL, the priority of the selected message shall be stored in the location referenced by<i>msg_prio</i>.</p><p>If the specified message queue is empty and O_NONBLOCK is not set in the message queue description associated with <i>mqdes</i>,<i>mq_receive</i>() shall block until a message is enqueued on the message queue or until <i>mq_receive</i>() is interrupted by asignal. If more than one thread is waiting to receive a message when a message arrives at an empty queue and the PriorityScheduling option is supported, then the thread of highest priority that has been waiting the longest shall be selected to receivethe message. Otherwise, it is unspecified which waiting thread receives the message. If the specified message queue is empty andO_NONBLOCK is set in the message queue description associated with <i>mqdes</i>, no message shall be removed from the queue, and<i>mq_receive</i>() shall return an error.</p><p><sup>[<a href="javascript:open_code('TMO')">TMO</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">The <i>mq_timedreceive</i>() function shall receive the oldest of the highest priority messages from the message queue specified by<i>mqdes</i> as described for the <i>mq_receive</i>() function. However, if O_NONBLOCK was not specified when the message queue wasopened via the <a href="../functions/mq_open.html"><i>mq_open</i>()</a> function, and no message exists on the queue to satisfy thereceive, the wait for such a message shall be terminated when the specified timeout expires. If O_NONBLOCK is set, this function isequivalent to <i>mq_receive</i>().</p><p>The timeout expires when the absolute time specified by <i>abs_timeout</i> passes, as measured by the clock on which timeoutsare based (that is, when the value of that clock equals or exceeds <i>abs_timeout</i>), or if the absolute time specified by<i>abs_timeout</i> has already been passed at the time of the call. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p><p><sup>[<a href="javascript:open_code('TMO TMR')">TMO TMR</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]"border="0"> If the Timers option is supported, the timeout shall be based on the CLOCK_REALTIME clock; if the Timers option is notsupported, the timeout shall be based on the system clock as returned by the <a href="../functions/time.html"><i>time</i>()</a>function. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p><p><sup>[<a href="javascript:open_code('TMO')">TMO</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">The resolution of the timeout shall be the resolution of the clock on which it is based. The <i>timespec</i> argument is defined inthe <a href="../basedefs/time.h.html"><i><time.h></i></a> header.</p><p>Under no circumstance shall the operation fail with a timeout if a message can be removed from the message queue immediately.The validity of the <i>abs_timeout</i> parameter need not be checked if a message can be removed from the message queueimmediately. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p></blockquote><h4><a name="tag_03_386_04"></a>RETURN VALUE</h4><blockquote><p>Upon successful completion, the <i>mq_receive</i>() <sup>[<a href="javascript:open_code('TMO')">TMO</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> and <i>mq_timedreceive</i>() <img src="../images/opt-end.gif" alt="[Option End]" border="0"> functions shall return the length of the selected message in bytes and the message shall be removed fromthe queue. Otherwise, no message shall be removed from the queue, the functions shall return a value of -1, and set <i>errno</i> toindicate the error.</p></blockquote><h4><a name="tag_03_386_05"></a>ERRORS</h4><blockquote><p>The <i>mq_receive</i>() <sup>[<a href="javascript:open_code('TMO')">TMO</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> and <i>mq_timedreceive</i>() <img src="../images/opt-end.gif" alt="[Option End]" border="0">functions shall fail if:</p><dl compact><dt>[EAGAIN]</dt><dd>O_NONBLOCK was set in the message description associated with <i>mqdes</i>, and the specified message queue is empty.</dd><dt>[EBADF]</dt><dd>The <i>mqdes</i> argument is not a valid message queue descriptor open for reading.</dd><dt>[EMSGSIZE]</dt><dd>The specified message buffer size, <i>msg_len</i>, is less than the message size attribute of the message queue.</dd><dt>[EINTR]</dt><dd>The <i>mq_receive</i>() <sup>[<a href="javascript:open_code('TMO')">TMO</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> or <i>mq_timedreceive</i>() <img src="../images/opt-end.gif" alt="[Option End]" border="0">operation was interrupted by a signal.</dd><dt>[EINVAL]</dt><dd><sup>[<a href="javascript:open_code('TMO')">TMO</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">The process or thread would have blocked, and the <i>abs_timeout</i> parameter specified a nanoseconds field value less than zeroor greater than or equal to 1000 million. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd><dt>[ETIMEDOUT]</dt><dd><sup>[<a href="javascript:open_code('TMO')">TMO</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">The O_NONBLOCK flag was not set when the message queue was opened, but no message arrived on the queue before the specified timeoutexpired. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd></dl><p>The <i>mq_receive</i>() <sup>[<a href="javascript:open_code('TMO')">TMO</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> and <i>mq_timedreceive</i>() <img src="../images/opt-end.gif" alt="[Option End]" border="0">functions may fail if:</p><dl compact><dt>[EBADMSG]</dt><dd>The implementation has detected a data corruption problem with the message.</dd></dl></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_386_06"></a>EXAMPLES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_386_07"></a>APPLICATION USAGE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_386_08"></a>RATIONALE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_386_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_386_10"></a>SEE ALSO</h4><blockquote><p><a href="mq_open.html"><i>mq_open</i>()</a> , <a href="mq_send.html"><i>mq_send</i>()</a> , <a href="mq_timedsend.html"><i>mq_timedsend</i>()</a> , <a href="msgctl.html"><i>msgctl</i>()</a> , <a href="msgget.html"><i>msgget</i>()</a> , <a href="msgrcv.html"><i>msgrcv</i>()</a> , <a href="msgsnd.html"><i>msgsnd</i>()</a> , <ahref="time.html"><i>time</i>()</a> , the Base Definitions volume of IEEE Std 1003.1-2001, <a href="../basedefs/mqueue.h.html"><i><mqueue.h></i></a>, <a href="../basedefs/time.h.html"><i><time.h></i></a></p></blockquote><h4><a name="tag_03_386_11"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 5. Included for alignment with the POSIX Realtime Extension.</p></blockquote><h4><a name="tag_03_386_12"></a>Issue 6</h4><blockquote><p>The <i>mq_receive</i>() function is marked as part of the Message Passing option.</p><p>The Open Group Corrigendum U021/4 is applied. The DESCRIPTION is changed to refer to <i>msg_len</i> rather than<i>maxsize</i>.</p><p>The [ENOSYS] error condition has been removed as stubs need not be provided if an implementation does not support the MessagePassing option.</p><p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p><ul><li><p>In this function it is possible for the return value to exceed the range of the type <b>ssize_t</b> (since <b>size_t</b> has alarger range of positive values than <b>ssize_t</b>). A sentence restricting the size of the <b>size_t</b> object is added to thedescription to resolve this conflict.</p></li></ul><p>The <i>mq_timedreceive</i>() function is added for alignment with IEEE Std 1003.1d-1999.</p><p>The <b>restrict</b> keyword is added to the <i>mq_timedreceive</i>() prototype for alignment with the ISO/IEC 9899:1999standard.</p><p>IEEE PASC Interpretation 1003.1 #109 is applied, correcting the return type for <i>mq_timedreceive</i>() from <b>int</b> to<b>ssize_t</b>.</p></blockquote><div class="box"><em>End of informative text.</em></div><hr><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX ® is a registered Trademark of The Open Group.<br>POSIX ® is a registered Trademark of The IEEE.<br>[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>]</font></center><!--footer end--><hr size="2" noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -