2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 .\" permission to reproduce portions of its copyrighted documentation.
4 .\" Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
14 .\" Portions of this text are reprinted and reproduced in electronic form
15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 .\" Standard for Information Technology -- Portable Operating System
17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 .\" Engineers, Inc and The Open Group. In the event of any discrepancy
20 .\" between these versions and the original IEEE and The Open Group
21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 .\" document. The original Standard can be obtained online at
23 .\" http://www.opengroup.org/unix/online.html.
25 .\" This notice shall appear on any product containing this material.
27 .\" The contents of this file are subject to the terms of the
28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
43 .\" Copyright 1989 AT&T
44 .\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved.
45 .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved.
47 .TH MQ_RECEIVE 3C "Feb 5, 2008"
49 mq_receive, mq_timedreceive, mq_reltimedreceive_np \- receive a message from a
56 \fBssize_t\fR \fBmq_receive\fR(\fBmqd_t\fR \fImqdes\fR, \fBchar *\fR\fImsg_ptr\fR, \fBsize_t\fR \fImsg_len\fR,
57 \fBunsigned *\fR\fImsg_prio\fR);
65 \fBssize_t\fR \fBmq_timedreceive\fR(\fBmqd_t\fR \fImqdes\fR, \fBchar *restrict\fR \fImsg_ptr\fR,
66 \fBsize_t\fR \fImsg_len\fR, \fBunsigned *restrict\fR \fImsg_prio\fR,
67 \fBconst struct timespec *restrict\fR \fIabs_timeout\fR);
72 \fBssize_t\fR \fBmq_reltimedreceive_np\fR(\fBmqd_t\fR \fImqdes\fR,
73 \fBchar *restrict\fR \fImsg_ptr\fR, \fBsize_t\fR \fImsg_len\fR,
74 \fBunsigned *restrict\fR \fImsg_prio\fR,
75 \fBconst struct timespec *restrict\fR \fIrel_timeout\fR);
81 The \fBmq_receive()\fR function receives the oldest of the highest priority
82 message(s) from the message queue specified by \fImqdes\fR. If the size of the
83 buffer in bytes, specified by \fImsg_len\fR, is less than the \fBmq_msgsize\fR
84 member of the message queue, the function fails and returns an error.
85 Otherwise, the selected message is removed from the queue and copied to the
86 buffer pointed to by \fImsg_ptr\fR.
89 If the value of \fImsg_len\fR is greater than {\fBSSIZE_MAX\fR}, the result is
90 implementation-defined.
93 If \fImsg_prio\fR is not \fINULL\fR, the priority of the selected message is
94 stored in the location referenced by \fImsg_prio\fR.
97 If the specified message queue is empty and \fBO_NONBLOCK\fR is not set in the
98 message queue description associated with \fImqdes\fR, (see \fBmq_open\fR(3C)
99 and \fBmq_setattr\fR(3C)), \fBmq_receive()\fR blocks, waiting until a message
100 is enqueued on the message queue, or until \fBmq_receive()\fR is interrupted by
101 a signal. If more than one process (or thread) is waiting to receive a message
102 when a message arrives at an empty queue, then the process of highest priority
103 that has been waiting the longest is selected to receive the message. If the
104 specified message queue is empty and \fBO_NONBLOCK\fR is set in the message
105 queue description associated with \fImqdes\fR, no message is removed from the
106 queue, and \fBmq_receive()\fR returns an error.
109 The \fBmq_timedreceive()\fR function receives the oldest of the highest
110 priority messages from the message queue specified by \fImqdes\fR as described
111 for the \fBmq_receive()\fR function. However, if \fBO_NONBLOCK\fR was not
112 specified when the message queue was opened with the \fBmq_open\fR(3C)
113 function, and no message exists on the queue to satisfy the receive, the wait
114 for such a message is terminated when the specified timeout expires. If
115 \fBO_NONBLOCK\fR is set, this function is equivalent to \fBmq_receive()\fR.
118 The \fBmq_reltimedreceive_np()\fR function is identical to the
119 \fBmq_timedreceive()\fR function, except that the timeout is specified as a
120 relative time interval.
123 For \fBmq_timedreceive()\fR, the timeout expires when the absolute time
124 specified by \fIabs_timeout\fR passes, as measured by the \fBCLOCK_REALTIME\fR
125 clock (that is, when the value of that clock equals or exceeds
126 \fIabs_timeout\fR), or if the absolute time specified by \fIabs_timeout\fR has
127 already been passed at the time of the call.
130 For \fBmq_reltimedreceive_np()\fR, the timeout expires when the time interval
131 specified by \fIrel_timeout\fR passes, as measured by the \fBCLOCK_REALTIME\fR
132 clock, or if the time interval specified by \fIrel_timeout\fR is negative at
133 the time of the call.
136 The resolution of the timeout is the resolution of the \fBCLOCK_REALTIME\fR
137 clock. The \fBtimespec\fR argument is defined in the <\fBtime.h\fR> header.
140 Under no circumstance does the operation fail with a timeout if a message can
141 be removed from the message queue immediately. The validity of the timeout
142 parameter need not be checked if a message can be removed from the message
147 Upon successful completion, \fBmq_receive()\fR, \fBmq_timedreceive()\fR, and
148 \fBmq_reltimedreceive_np()\fR return the length of the selected message in
149 bytes and the message is removed from the queue. Otherwise, no message is
150 removed from the queue, the functions return a value of \fB\(mi1\fR, and sets
151 \fBerrno\fR to indicate the error condition.
155 The \fBmq_receive()\fR, \fBmq_timedreceive()\fR, and
156 \fBmq_reltimedreceive_np()\fR functions will fail if:
163 \fBO_NONBLOCK\fR was set in the message description associated with
164 \fImqdes\fR, and the specified message queue is empty.
173 The \fImqdes\fR argument is not a valid message queue descriptor open for
183 The function was interrupted by a signal.
192 The process or thread would have blocked, and the timeout parameter specified a
193 nanoseconds field value less than zero or greater than or equal to 1,000
200 \fB\fBEMSGSIZE\fR \fR
203 The specified message buffer size, \fImsg_len\fR, is less than the message size
204 member of the message queue.
210 \fB\fBETIMEDOUT\fR\fR
213 The \fBO_NONBLOCK\fR flag was not set when the message queue was opened, but no
214 message arrived on the queue before the specified timeout expired.
219 The \fBmq_receive()\fR, \fBmq_timedreceive()\fR, and
220 \fBmq_reltimedreceive_np()\fR functions may fail if:
227 A data corruption problem with the message has been detected.
233 See \fBattributes\fR(5) for descriptions of the following attributes:
241 ATTRIBUTE TYPE ATTRIBUTE VALUE
243 Interface Stability Committed
252 For \fBmq_receive()\fR and \fBmq_timedreceive()\fR. see \fBstandards\fR(5).
256 \fBmqueue.h\fR(3HEAD), \fBmq_open\fR(3C), \fBmq_send\fR(3C),
257 \fBmq_setattr\fR(3C), \fBattributes\fR(5), \fBstandards\fR(5)