xref: /freebsd/lib/libsys/mq_receive.2 (revision 8269e7673cf033aba67dab8264fe719920c70f87)
1*8269e767SBrooks Davis.\" Copyright (c) 2005 David Xu <davidxu@FreeBSD.org>
2*8269e767SBrooks Davis.\" All rights reserved.
3*8269e767SBrooks Davis.\"
4*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without
5*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions
6*8269e767SBrooks Davis.\" are met:
7*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright
8*8269e767SBrooks Davis.\"    notice(s), this list of conditions and the following disclaimer as
9*8269e767SBrooks Davis.\"    the first lines of this file unmodified other than the possible
10*8269e767SBrooks Davis.\"    addition of one or more copyright notices.
11*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright
12*8269e767SBrooks Davis.\"    notice(s), this list of conditions and the following disclaimer in
13*8269e767SBrooks Davis.\"    the documentation and/or other materials provided with the
14*8269e767SBrooks Davis.\"    distribution.
15*8269e767SBrooks Davis.\"
16*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
17*8269e767SBrooks Davis.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*8269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19*8269e767SBrooks Davis.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
20*8269e767SBrooks Davis.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21*8269e767SBrooks Davis.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22*8269e767SBrooks Davis.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23*8269e767SBrooks Davis.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24*8269e767SBrooks Davis.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25*8269e767SBrooks Davis.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26*8269e767SBrooks Davis.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*8269e767SBrooks Davis.\"
28*8269e767SBrooks Davis.\" Portions of this text are reprinted and reproduced in electronic form
29*8269e767SBrooks Davis.\" from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology --
30*8269e767SBrooks Davis.\" Portable Operating System Interface (POSIX), The Open Group Base
31*8269e767SBrooks Davis.\" Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of
32*8269e767SBrooks Davis.\" Electrical and Electronics Engineers, Inc and The Open Group.  In the
33*8269e767SBrooks Davis.\" event of any discrepancy between this version and the original IEEE and
34*8269e767SBrooks Davis.\" The Open Group Standard, the original IEEE and The Open Group Standard is
35*8269e767SBrooks Davis.\" the referee document.  The original Standard can be obtained online at
36*8269e767SBrooks Davis.\"	http://www.opengroup.org/unix/online.html.
37*8269e767SBrooks Davis.\"
38*8269e767SBrooks Davis.Dd November 29, 2005
39*8269e767SBrooks Davis.Dt MQ_RECEIVE 2
40*8269e767SBrooks Davis.Os
41*8269e767SBrooks Davis.Sh NAME
42*8269e767SBrooks Davis.Nm mq_receive , mq_timedreceive
43*8269e767SBrooks Davis.Nd "receive a message from message queue (REALTIME)"
44*8269e767SBrooks Davis.Sh LIBRARY
45*8269e767SBrooks Davis.Lb librt
46*8269e767SBrooks Davis.Sh SYNOPSIS
47*8269e767SBrooks Davis.In mqueue.h
48*8269e767SBrooks Davis.Ft ssize_t
49*8269e767SBrooks Davis.Fo mq_receive
50*8269e767SBrooks Davis.Fa "mqd_t mqdes"
51*8269e767SBrooks Davis.Fa "char *msg_ptr"
52*8269e767SBrooks Davis.Fa "size_t msg_len"
53*8269e767SBrooks Davis.Fa "unsigned *msg_prio"
54*8269e767SBrooks Davis.Fc
55*8269e767SBrooks Davis.Ft ssize_t
56*8269e767SBrooks Davis.Fo mq_timedreceive
57*8269e767SBrooks Davis.Fa "mqd_t mqdes"
58*8269e767SBrooks Davis.Fa "char *msg_ptr"
59*8269e767SBrooks Davis.Fa "size_t msg_len"
60*8269e767SBrooks Davis.Fa "unsigned *msg_prio"
61*8269e767SBrooks Davis.Fa "const struct timespec *abs_timeout"
62*8269e767SBrooks Davis.Fc
63*8269e767SBrooks Davis.Sh DESCRIPTION
64*8269e767SBrooks DavisThe
65*8269e767SBrooks Davis.Fn mq_receive
66*8269e767SBrooks Davissystem call receives oldest of the highest priority message(s) from the
67*8269e767SBrooks Davismessage queue specified by
68*8269e767SBrooks Davis.Fa mqdes .
69*8269e767SBrooks DavisIf the size of the buffer in bytes, specified by the
70*8269e767SBrooks Davis.Fa msg_len
71*8269e767SBrooks Davisargument, is less than the
72*8269e767SBrooks Davis.Va mq_msgsize
73*8269e767SBrooks Davisattribute of the message queue, the system call will fail and return an
74*8269e767SBrooks Daviserror.
75*8269e767SBrooks DavisOtherwise, the selected message will be removed from the queue
76*8269e767SBrooks Davisand copied to the buffer pointed to by the
77*8269e767SBrooks Davis.Fa msg_ptr
78*8269e767SBrooks Davisargument.
79*8269e767SBrooks Davis.Pp
80*8269e767SBrooks DavisIf the argument
81*8269e767SBrooks Davis.Fa msg_prio
82*8269e767SBrooks Davisis not
83*8269e767SBrooks Davis.Dv NULL ,
84*8269e767SBrooks Davisthe priority of the selected message will be stored in the
85*8269e767SBrooks Davislocation referenced by
86*8269e767SBrooks Davis.Fa msg_prio .
87*8269e767SBrooks DavisIf the specified message queue is empty and
88*8269e767SBrooks Davis.Dv O_NONBLOCK
89*8269e767SBrooks Davisis not set in the message queue description associated with
90*8269e767SBrooks Davis.Fa mqdes ,
91*8269e767SBrooks Davis.Fn mq_receive
92*8269e767SBrooks Daviswill block until a message is enqueued on the message queue or until
93*8269e767SBrooks Davis.Fn mq_receive
94*8269e767SBrooks Davisis interrupted by a signal.
95*8269e767SBrooks DavisIf more than one thread is waiting to receive
96*8269e767SBrooks Davisa message when a message arrives at an empty queue and the Priority
97*8269e767SBrooks DavisScheduling option is supported, then the thread of highest priority that
98*8269e767SBrooks Davishas been waiting the longest will be selected to receive the message.
99*8269e767SBrooks DavisOtherwise, it is unspecified which waiting thread receives the message.
100*8269e767SBrooks DavisIf the specified message queue is empty and
101*8269e767SBrooks Davis.Dv O_NONBLOCK
102*8269e767SBrooks Davisis set in the message queue description associated with
103*8269e767SBrooks Davis.Fa mqdes ,
104*8269e767SBrooks Davisno message
105*8269e767SBrooks Daviswill be removed from the queue, and
106*8269e767SBrooks Davis.Fn mq_receive
107*8269e767SBrooks Daviswill return an error.
108*8269e767SBrooks Davis.Pp
109*8269e767SBrooks DavisThe
110*8269e767SBrooks Davis.Fn mq_timedreceive
111*8269e767SBrooks Davissystem call will receive the oldest of the highest priority messages from the
112*8269e767SBrooks Davismessage queue specified by
113*8269e767SBrooks Davis.Fa mqdes
114*8269e767SBrooks Davisas described for the
115*8269e767SBrooks Davis.Fn mq_receive
116*8269e767SBrooks Davissystem call.
117*8269e767SBrooks DavisHowever, if
118*8269e767SBrooks Davis.Dv O_NONBLOCK
119*8269e767SBrooks Daviswas not specified when the message queue was opened via the
120*8269e767SBrooks Davis.Fn mq_open
121*8269e767SBrooks Davissystem call, and no message exists on the queue to satisfy the receive, the wait
122*8269e767SBrooks Davisfor such a message will be terminated when the specified timeout expires.
123*8269e767SBrooks DavisIf
124*8269e767SBrooks Davis.Dv O_NONBLOCK
125*8269e767SBrooks Davisis set, this system call is equivalent to
126*8269e767SBrooks Davis.Fn mq_receive .
127*8269e767SBrooks Davis.Pp
128*8269e767SBrooks DavisThe timeout expires when the absolute time specified by
129*8269e767SBrooks Davis.Fa abs_timeout
130*8269e767SBrooks Davispasses, as measured by the clock on which timeouts are based (that is, when
131*8269e767SBrooks Davisthe value of that clock equals or exceeds
132*8269e767SBrooks Davis.Fa abs_timeout ) ,
133*8269e767SBrooks Davisor if the absolute time specified by
134*8269e767SBrooks Davis.Fa abs_timeout
135*8269e767SBrooks Davishas already been passed at the time of the call.
136*8269e767SBrooks Davis.Pp
137*8269e767SBrooks DavisThe timeout is based on the
138*8269e767SBrooks Davis.Dv CLOCK_REALTIME
139*8269e767SBrooks Davisclock.
140*8269e767SBrooks Davis.Sh RETURN VALUES
141*8269e767SBrooks DavisUpon successful completion, the
142*8269e767SBrooks Davis.Fn mq_receive
143*8269e767SBrooks Davisand
144*8269e767SBrooks Davis.Fn mq_timedreceive
145*8269e767SBrooks Davissystem calls return the length of the selected message in bytes and the
146*8269e767SBrooks Davismessage is removed from the queue.
147*8269e767SBrooks DavisOtherwise, no message is removed
148*8269e767SBrooks Davisfrom the queue, the system call returns a value of \-1,
149*8269e767SBrooks Davisand the global variable
150*8269e767SBrooks Davis.Va errno
151*8269e767SBrooks Davisis set to indicate the error.
152*8269e767SBrooks Davis.Sh ERRORS
153*8269e767SBrooks DavisThe
154*8269e767SBrooks Davis.Fn mq_receive
155*8269e767SBrooks Davisand
156*8269e767SBrooks Davis.Fn mq_timedreceive
157*8269e767SBrooks Davissystem calls
158*8269e767SBrooks Daviswill fail if:
159*8269e767SBrooks Davis.Bl -tag -width Er
160*8269e767SBrooks Davis.It Bq Er EAGAIN
161*8269e767SBrooks Davis.Dv O_NONBLOCK
162*8269e767SBrooks Davisflag is set in the message queue description associated with
163*8269e767SBrooks Davis.Fa mqdes ,
164*8269e767SBrooks Davisand the specified message queue is empty.
165*8269e767SBrooks Davis.It Bq Er EBADF
166*8269e767SBrooks DavisThe
167*8269e767SBrooks Davis.Fa mqdes
168*8269e767SBrooks Davisargument is not a valid message queue descriptor open for reading.
169*8269e767SBrooks Davis.It Bq Er EMSGSIZE
170*8269e767SBrooks DavisThe specified message buffer size,
171*8269e767SBrooks Davis.Fa msg_len ,
172*8269e767SBrooks Davisis less than the message size attribute of the message queue.
173*8269e767SBrooks Davis.It Bq Er EINTR
174*8269e767SBrooks DavisThe
175*8269e767SBrooks Davis.Fn mq_receive
176*8269e767SBrooks Davisor
177*8269e767SBrooks Davis.Fn mq_timedreceive
178*8269e767SBrooks Davisoperation was interrupted by a signal.
179*8269e767SBrooks Davis.It Bq Er EINVAL
180*8269e767SBrooks DavisThe process or thread would have blocked, and the
181*8269e767SBrooks Davis.Fa abs_timeout
182*8269e767SBrooks Davisparameter specified a nanoseconds field value less than zero or greater
183*8269e767SBrooks Davisthan or equal to 1000 million.
184*8269e767SBrooks Davis.It Bq Er ETIMEDOUT
185*8269e767SBrooks DavisThe
186*8269e767SBrooks Davis.Dv O_NONBLOCK
187*8269e767SBrooks Davisflag was not set when the message queue was opened, but no message arrived
188*8269e767SBrooks Davison the queue before the specified timeout expired.
189*8269e767SBrooks Davis.El
190*8269e767SBrooks Davis.Sh SEE ALSO
191*8269e767SBrooks Davis.Xr mq_open 2 ,
192*8269e767SBrooks Davis.Xr mq_send 2 ,
193*8269e767SBrooks Davis.Xr mq_timedsend 2
194*8269e767SBrooks Davis.Sh STANDARDS
195*8269e767SBrooks DavisThe
196*8269e767SBrooks Davis.Fn mq_receive
197*8269e767SBrooks Davisand
198*8269e767SBrooks Davis.Fn mq_timedreceive
199*8269e767SBrooks Davissystem calls conform to
200*8269e767SBrooks Davis.St -p1003.1-2004 .
201*8269e767SBrooks Davis.Sh HISTORY
202*8269e767SBrooks DavisSupport for
203*8269e767SBrooks Davis.Tn POSIX
204*8269e767SBrooks Davismessage queues first appeared in
205*8269e767SBrooks Davis.Fx 7.0 .
206*8269e767SBrooks Davis.Sh COPYRIGHT
207*8269e767SBrooks DavisPortions of this text are reprinted and reproduced in electronic form
208*8269e767SBrooks Davisfrom IEEE Std 1003.1, 2004 Edition, Standard for Information Technology --
209*8269e767SBrooks DavisPortable Operating System Interface (POSIX), The Open Group Base
210*8269e767SBrooks DavisSpecifications Issue 6, Copyright (C) 2001-2004 by the Institute of
211*8269e767SBrooks DavisElectrical and Electronics Engineers, Inc and The Open Group.  In the
212*8269e767SBrooks Davisevent of any discrepancy between this version and the original IEEE and
213*8269e767SBrooks DavisThe Open Group Standard, the original IEEE and The Open Group Standard is
214*8269e767SBrooks Davisthe referee document.  The original Standard can be obtained online at
215*8269e767SBrooks Davishttp://www.opengroup.org/unix/online.html.
216