9103 opengroup acknowledgement should be properly formatted in man pages
[unleashed.git] / usr / src / man / man3c / mq_receive.3c
blob22483492906e434551387a955ae54e8cc9fc4d06
1 .\"
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/.
6 .\"
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
9 .\" documentation.
10 .\"
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
13 .\"
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.
24 .\"
25 .\" This notice shall appear on any product containing this material.
26 .\"
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.
30 .\"
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.
35 .\"
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]
41 .\"
42 .\"
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.
46 .\"
47 .TH MQ_RECEIVE 3C "Feb 5, 2008"
48 .SH NAME
49 mq_receive, mq_timedreceive, mq_reltimedreceive_np \- receive a message from a
50 message queue
51 .SH SYNOPSIS
52 .LP
53 .nf
54 #include <mqueue.h>
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);
58 .fi
60 .LP
61 .nf
62 #include <mqueue.h>
63 #include <time.h>
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);
68 .fi
70 .LP
71 .nf
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);
76 .fi
78 .SH DESCRIPTION
79 .sp
80 .LP
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.
87 .sp
88 .LP
89 If the value of \fImsg_len\fR is greater than {\fBSSIZE_MAX\fR}, the result is
90 implementation-defined.
91 .sp
92 .LP
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.
95 .sp
96 .LP
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
143 queue immediately.
144 .SH RETURN VALUES
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.
152 .SH ERRORS
155 The \fBmq_receive()\fR, \fBmq_timedreceive()\fR, and
156 \fBmq_reltimedreceive_np()\fR functions will fail if:
158 .ne 2
160 \fB\fBEAGAIN\fR \fR
162 .RS 13n
163 \fBO_NONBLOCK\fR was set in the message description associated with
164 \fImqdes\fR, and the specified message queue is empty.
168 .ne 2
170 \fB\fBEBADF\fR \fR
172 .RS 13n
173 The \fImqdes\fR argument is not a valid message queue descriptor open for
174 reading.
178 .ne 2
180 \fB\fBEINTR\fR \fR
182 .RS 13n
183 The function was interrupted by a signal.
187 .ne 2
189 \fB\fBEINVAL\fR\fR
191 .RS 13n
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
194 million.
198 .ne 2
200 \fB\fBEMSGSIZE\fR \fR
202 .RS 13n
203 The specified message buffer size, \fImsg_len\fR, is less than the message size
204 member of the message queue.
208 .ne 2
210 \fB\fBETIMEDOUT\fR\fR
212 .RS 13n
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:
222 .ne 2
224 \fB\fBEBADMSG\fR \fR
226 .RS 12n
227 A data corruption problem with the message has been detected.
230 .SH ATTRIBUTES
233 See \fBattributes\fR(5) for descriptions of the following attributes:
238 box;
239 l | l
240 l | l .
241 ATTRIBUTE TYPE  ATTRIBUTE VALUE
243 Interface Stability     Committed
245 MT-Level        MT-Safe
247 Standard        See below.
252 For \fBmq_receive()\fR and \fBmq_timedreceive()\fR. see \fBstandards\fR(5).
253 .SH SEE ALSO
256 \fBmqueue.h\fR(3HEAD), \fBmq_open\fR(3C), \fBmq_send\fR(3C),
257 \fBmq_setattr\fR(3C), \fBattributes\fR(5), \fBstandards\fR(5)