2 .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved.
3 .\" Copyright 1989 AT&T
4 .\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved.
5 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
6 .\" http://www.opengroup.org/bookstore/.
7 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
8 .\" This notice shall appear on any product containing this material.
9 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
10 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
11 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
12 .TH MQ_RECEIVE 3C "Feb 5, 2008"
14 mq_receive, mq_timedreceive, mq_reltimedreceive_np \- receive a message from a
21 \fBssize_t\fR \fBmq_receive\fR(\fBmqd_t\fR \fImqdes\fR, \fBchar *\fR\fImsg_ptr\fR, \fBsize_t\fR \fImsg_len\fR,
22 \fBunsigned *\fR\fImsg_prio\fR);
30 \fBssize_t\fR \fBmq_timedreceive\fR(\fBmqd_t\fR \fImqdes\fR, \fBchar *restrict\fR \fImsg_ptr\fR,
31 \fBsize_t\fR \fImsg_len\fR, \fBunsigned *restrict\fR \fImsg_prio\fR,
32 \fBconst struct timespec *restrict\fR \fIabs_timeout\fR);
37 \fBssize_t\fR \fBmq_reltimedreceive_np\fR(\fBmqd_t\fR \fImqdes\fR,
38 \fBchar *restrict\fR \fImsg_ptr\fR, \fBsize_t\fR \fImsg_len\fR,
39 \fBunsigned *restrict\fR \fImsg_prio\fR,
40 \fBconst struct timespec *restrict\fR \fIrel_timeout\fR);
46 The \fBmq_receive()\fR function receives the oldest of the highest priority
47 message(s) from the message queue specified by \fImqdes\fR. If the size of the
48 buffer in bytes, specified by \fImsg_len\fR, is less than the \fBmq_msgsize\fR
49 member of the message queue, the function fails and returns an error.
50 Otherwise, the selected message is removed from the queue and copied to the
51 buffer pointed to by \fImsg_ptr\fR.
54 If the value of \fImsg_len\fR is greater than {\fBSSIZE_MAX\fR}, the result is
55 implementation-defined.
58 If \fImsg_prio\fR is not \fINULL\fR, the priority of the selected message is
59 stored in the location referenced by \fImsg_prio\fR.
62 If the specified message queue is empty and \fBO_NONBLOCK\fR is not set in the
63 message queue description associated with \fImqdes\fR, (see \fBmq_open\fR(3C)
64 and \fBmq_setattr\fR(3C)), \fBmq_receive()\fR blocks, waiting until a message
65 is enqueued on the message queue, or until \fBmq_receive()\fR is interrupted by
66 a signal. If more than one process (or thread) is waiting to receive a message
67 when a message arrives at an empty queue, then the process of highest priority
68 that has been waiting the longest is selected to receive the message. If the
69 specified message queue is empty and \fBO_NONBLOCK\fR is set in the message
70 queue description associated with \fImqdes\fR, no message is removed from the
71 queue, and \fBmq_receive()\fR returns an error.
74 The \fBmq_timedreceive()\fR function receives the oldest of the highest
75 priority messages from the message queue specified by \fImqdes\fR as described
76 for the \fBmq_receive()\fR function. However, if \fBO_NONBLOCK\fR was not
77 specified when the message queue was opened with the \fBmq_open\fR(3C)
78 function, and no message exists on the queue to satisfy the receive, the wait
79 for such a message is terminated when the specified timeout expires. If
80 \fBO_NONBLOCK\fR is set, this function is equivalent to \fBmq_receive()\fR.
83 The \fBmq_reltimedreceive_np()\fR function is identical to the
84 \fBmq_timedreceive()\fR function, except that the timeout is specified as a
85 relative time interval.
88 For \fBmq_timedreceive()\fR, the timeout expires when the absolute time
89 specified by \fIabs_timeout\fR passes, as measured by the \fBCLOCK_REALTIME\fR
90 clock (that is, when the value of that clock equals or exceeds
91 \fIabs_timeout\fR), or if the absolute time specified by \fIabs_timeout\fR has
92 already been passed at the time of the call.
95 For \fBmq_reltimedreceive_np()\fR, the timeout expires when the time interval
96 specified by \fIrel_timeout\fR passes, as measured by the \fBCLOCK_REALTIME\fR
97 clock, or if the time interval specified by \fIrel_timeout\fR is negative at
101 The resolution of the timeout is the resolution of the \fBCLOCK_REALTIME\fR
102 clock. The \fBtimespec\fR argument is defined in the <\fBtime.h\fR> header.
105 Under no circumstance does the operation fail with a timeout if a message can
106 be removed from the message queue immediately. The validity of the timeout
107 parameter need not be checked if a message can be removed from the message
112 Upon successful completion, \fBmq_receive()\fR, \fBmq_timedreceive()\fR, and
113 \fBmq_reltimedreceive_np()\fR return the length of the selected message in
114 bytes and the message is removed from the queue. Otherwise, no message is
115 removed from the queue, the functions return a value of \fB\(mi1\fR, and sets
116 \fBerrno\fR to indicate the error condition.
120 The \fBmq_receive()\fR, \fBmq_timedreceive()\fR, and
121 \fBmq_reltimedreceive_np()\fR functions will fail if:
128 \fBO_NONBLOCK\fR was set in the message description associated with
129 \fImqdes\fR, and the specified message queue is empty.
138 The \fImqdes\fR argument is not a valid message queue descriptor open for
148 The function was interrupted by a signal.
157 The process or thread would have blocked, and the timeout parameter specified a
158 nanoseconds field value less than zero or greater than or equal to 1,000
165 \fB\fBEMSGSIZE\fR \fR
168 The specified message buffer size, \fImsg_len\fR, is less than the message size
169 member of the message queue.
175 \fB\fBETIMEDOUT\fR\fR
178 The \fBO_NONBLOCK\fR flag was not set when the message queue was opened, but no
179 message arrived on the queue before the specified timeout expired.
184 The \fBmq_receive()\fR, \fBmq_timedreceive()\fR, and
185 \fBmq_reltimedreceive_np()\fR functions may fail if:
192 A data corruption problem with the message has been detected.
198 See \fBattributes\fR(5) for descriptions of the following attributes:
206 ATTRIBUTE TYPE ATTRIBUTE VALUE
208 Interface Stability Committed
217 For \fBmq_receive()\fR and \fBmq_timedreceive()\fR. see \fBstandards\fR(5).
221 \fBmqueue.h\fR(3HEAD), \fBmq_open\fR(3C), \fBmq_send\fR(3C),
222 \fBmq_setattr\fR(3C), \fBattributes\fR(5), \fBstandards\fR(5)