xref: /dflybsd-src/lib/librt/mq_receive.2 (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
1*86d7f5d3SJohn Marino.\"	$NetBSD: mq_receive.3,v 1.1 2009/01/05 21:19:49 rmind Exp $
2*86d7f5d3SJohn Marino.\"
3*86d7f5d3SJohn Marino.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved
4*86d7f5d3SJohn Marino.\"
5*86d7f5d3SJohn Marino.Dd August 19, 2009
6*86d7f5d3SJohn Marino.Dt MQ_RECEIVE 2
7*86d7f5d3SJohn Marino.Os
8*86d7f5d3SJohn Marino.Sh NAME
9*86d7f5d3SJohn Marino.Nm mq_receive , mq_timedreceive
10*86d7f5d3SJohn Marino.Nd receive a message from a message queue (REALTIME)
11*86d7f5d3SJohn Marino.Sh LIBRARY
12*86d7f5d3SJohn Marino.Lb librt
13*86d7f5d3SJohn Marino.Sh SYNOPSIS
14*86d7f5d3SJohn Marino.In mqueue.h
15*86d7f5d3SJohn Marino.Ft ssize_t
16*86d7f5d3SJohn Marino.Fo mq_receive
17*86d7f5d3SJohn Marino.Fa "mqd_t mqdes"
18*86d7f5d3SJohn Marino.Fa "char *msg_ptr"
19*86d7f5d3SJohn Marino.Fa "size_t msg_len"
20*86d7f5d3SJohn Marino.Fa "unsigned *msg_prio"
21*86d7f5d3SJohn Marino.Fc
22*86d7f5d3SJohn Marino.In mqueue.h
23*86d7f5d3SJohn Marino.In time.h
24*86d7f5d3SJohn Marino.Ft ssize_t
25*86d7f5d3SJohn Marino.Fo mq_timedreceive
26*86d7f5d3SJohn Marino.Fa "mqd_t mqdes"
27*86d7f5d3SJohn Marino.Fa "char *restrict msg_ptr"
28*86d7f5d3SJohn Marino.Fa "size_t msg_len"
29*86d7f5d3SJohn Marino.Fa "unsigned *restrict msg_prio"
30*86d7f5d3SJohn Marino.Fa "const struct timespec *restrict abs_timeout"
31*86d7f5d3SJohn Marino.Fc
32*86d7f5d3SJohn Marino.Sh DESCRIPTION
33*86d7f5d3SJohn MarinoThe
34*86d7f5d3SJohn Marino.Fn mq_receive
35*86d7f5d3SJohn Marinofunction receives the oldest of the highest priority message(s)
36*86d7f5d3SJohn Marinofrom the message queue specified by
37*86d7f5d3SJohn Marino.Fa mqdes .
38*86d7f5d3SJohn MarinoIf the size of the buffer in bytes, specified by the
39*86d7f5d3SJohn Marino.Fa msg_len
40*86d7f5d3SJohn Marinoargument, is less than the
41*86d7f5d3SJohn Marino.Va mq_msgsize
42*86d7f5d3SJohn Marinoattribute of the message queue, the function fails and returns an error.
43*86d7f5d3SJohn MarinoOtherwise, the selected message will be removed from the queue and copied
44*86d7f5d3SJohn Marinoto the buffer pointed to by the
45*86d7f5d3SJohn Marino.Fa msg_ptr
46*86d7f5d3SJohn Marinoargument.
47*86d7f5d3SJohn Marino.Pp
48*86d7f5d3SJohn MarinoIf the argument
49*86d7f5d3SJohn Marino.Fa msg_prio
50*86d7f5d3SJohn Marinois not
51*86d7f5d3SJohn Marino.Dv NULL ,
52*86d7f5d3SJohn Marinothe priority of the selected message will be stored in the location
53*86d7f5d3SJohn Marinoreferenced by
54*86d7f5d3SJohn Marino.Fa msg_prio .
55*86d7f5d3SJohn Marino.Pp
56*86d7f5d3SJohn MarinoIf the specified message queue is empty and
57*86d7f5d3SJohn Marino.Dv O_NONBLOCK
58*86d7f5d3SJohn Marinois not set in the message queue description associated with
59*86d7f5d3SJohn Marino.Fa mqdes ,
60*86d7f5d3SJohn Marino.Fn mq_receive
61*86d7f5d3SJohn Marinoblocks until a message is enqueued on the message queue or until
62*86d7f5d3SJohn Marino.Fn mq_receive
63*86d7f5d3SJohn Marinois interrupted by a signal.
64*86d7f5d3SJohn MarinoIf more than one thread is waiting to receive a message when a
65*86d7f5d3SJohn Marinomessage arrives at an empty queue, then the thread of highest
66*86d7f5d3SJohn Marinopriority that has been waiting the longest will be selected to
67*86d7f5d3SJohn Marinoreceive the message.
68*86d7f5d3SJohn MarinoIf the specified message queue is empty and
69*86d7f5d3SJohn Marino.Dv O_NONBLOCK
70*86d7f5d3SJohn Marinois set in the message queue description associated with
71*86d7f5d3SJohn Marino.Fa mqdes ,
72*86d7f5d3SJohn Marinono message will be removed from the queue, and
73*86d7f5d3SJohn Marino.Fn mq_receive
74*86d7f5d3SJohn Marinoreturns an error.
75*86d7f5d3SJohn Marino.Pp
76*86d7f5d3SJohn MarinoThe timeout expires when the absolute time specified by
77*86d7f5d3SJohn Marino.Fa abs_timeout
78*86d7f5d3SJohn Marinopasses, as measured by the clock on which timeouts are based (that is,
79*86d7f5d3SJohn Marinowhen the value of that clock equals or exceeds
80*86d7f5d3SJohn Marino.Fa abs_timeout ) ,
81*86d7f5d3SJohn Marinoor if the absolute time specified by
82*86d7f5d3SJohn Marino.Fa abs_timeout
83*86d7f5d3SJohn Marinohas already been passed at the time of the call.
84*86d7f5d3SJohn Marino.Pp
85*86d7f5d3SJohn MarinoThe resolution of the timeout is based on the CLOCK_REALTIME clock.
86*86d7f5d3SJohn MarinoThe
87*86d7f5d3SJohn Marino.Fa timespec
88*86d7f5d3SJohn Marinoargument is defined in the
89*86d7f5d3SJohn Marino.Aq time.h
90*86d7f5d3SJohn Marinoheader.
91*86d7f5d3SJohn Marino.Pp
92*86d7f5d3SJohn MarinoUnder no circumstance will the operation fail with a timeout if a
93*86d7f5d3SJohn Marinomessage can be removed from the message queue immediately.
94*86d7f5d3SJohn MarinoThe validity of the
95*86d7f5d3SJohn Marino.Fa abs_timeout
96*86d7f5d3SJohn Marinoparameter will not be checked if a message can be removed from the
97*86d7f5d3SJohn Marinomessage queue immediately.
98*86d7f5d3SJohn Marino.Sh RETURN VALUES
99*86d7f5d3SJohn MarinoUpon successful completion, the
100*86d7f5d3SJohn Marino.Fn mq_receive
101*86d7f5d3SJohn Marinoand
102*86d7f5d3SJohn Marino.Fn mq_timedreceive
103*86d7f5d3SJohn Marinofunctions return a value of zero.
104*86d7f5d3SJohn MarinoOtherwise, no message will be removed from the queue,
105*86d7f5d3SJohn Marinothe functions return a value of
106*86d7f5d3SJohn Marino\-1, and set the global variable
107*86d7f5d3SJohn Marino.Va errno
108*86d7f5d3SJohn Marinoto indicate the error.
109*86d7f5d3SJohn Marino.Sh ERRORS
110*86d7f5d3SJohn MarinoThe
111*86d7f5d3SJohn Marino.Fn mq_receive
112*86d7f5d3SJohn Marinoand
113*86d7f5d3SJohn Marino.Fn mq_timedreceive
114*86d7f5d3SJohn Marinofunctions fail if:
115*86d7f5d3SJohn Marino.Bl -tag -width Er
116*86d7f5d3SJohn Marino.It Bq Er EAGAIN
117*86d7f5d3SJohn Marino.Dv O_NONBLOCK
118*86d7f5d3SJohn Marinowas set in the message description associated with
119*86d7f5d3SJohn Marino.Fa mqdes ,
120*86d7f5d3SJohn Marinoand the specified message queue is empty.
121*86d7f5d3SJohn Marino.It Bq Er EBADF
122*86d7f5d3SJohn MarinoThe
123*86d7f5d3SJohn Marino.Fa mqdes
124*86d7f5d3SJohn Marinoargument is not a valid message queue descriptor open for reading.
125*86d7f5d3SJohn Marino.It Bq Er EINTR
126*86d7f5d3SJohn MarinoThe
127*86d7f5d3SJohn Marino.Fn mq_receive
128*86d7f5d3SJohn Marinoor
129*86d7f5d3SJohn Marino.Fn mq_timedreceive
130*86d7f5d3SJohn Marinooperation was interrupted by a signal.
131*86d7f5d3SJohn Marino.It Bq Er EINVAL
132*86d7f5d3SJohn MarinoThe process or thread would have blocked, and the
133*86d7f5d3SJohn Marino.Fa abs_timeout
134*86d7f5d3SJohn Marinoparameter specified a nanoseconds field value less than zero
135*86d7f5d3SJohn Marinoor greater than or equal to 1000 million.
136*86d7f5d3SJohn Marino.It Bq Er EMSGSIZE
137*86d7f5d3SJohn MarinoThe specified message buffer size,
138*86d7f5d3SJohn Marino.Fa msg_len ,
139*86d7f5d3SJohn Marinois less than the message size attribute of the message queue.
140*86d7f5d3SJohn Marino.It Bq Er ETIMEDOUT
141*86d7f5d3SJohn MarinoThe
142*86d7f5d3SJohn Marino.Dv O_NONBLOCK
143*86d7f5d3SJohn Marinoflag was not set when the message queue was opened,
144*86d7f5d3SJohn Marinobut no message arrived on the queue before the specified timeout expired.
145*86d7f5d3SJohn Marino.El
146*86d7f5d3SJohn Marino.Sh SEE ALSO
147*86d7f5d3SJohn Marino.Xr mq_close 2 ,
148*86d7f5d3SJohn Marino.Xr mq_getattr 2 ,
149*86d7f5d3SJohn Marino.Xr mq_notify 2 ,
150*86d7f5d3SJohn Marino.Xr mq_open 2 ,
151*86d7f5d3SJohn Marino.Xr mq_send 2 ,
152*86d7f5d3SJohn Marino.Xr mq_setattr 2 ,
153*86d7f5d3SJohn Marino.Xr mq_unlink 2
154*86d7f5d3SJohn Marino.Sh STANDARDS
155*86d7f5d3SJohn MarinoThese functions are expected to conform to the
156*86d7f5d3SJohn Marino.St -p1003.1-2001
157*86d7f5d3SJohn Marinostandard.
158*86d7f5d3SJohn Marino.Sh HISTORY
159*86d7f5d3SJohn MarinoThe
160*86d7f5d3SJohn Marino.Fn mq_receive
161*86d7f5d3SJohn Marinoand
162*86d7f5d3SJohn Marino.Fn mq_timedreceive
163*86d7f5d3SJohn Marinofunctions first appeared in
164*86d7f5d3SJohn Marino.Dx 2.5 .
165*86d7f5d3SJohn Marino.Sh COPYRIGHT
166*86d7f5d3SJohn MarinoPortions of this text are reprinted and reproduced in electronic form
167*86d7f5d3SJohn Marinofrom IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
168*86d7f5d3SJohn Marino-- Portable Operating System Interface (POSIX), The Open Group Base
169*86d7f5d3SJohn MarinoSpecifications Issue 6, Copyright (C) 2001-2003 by the Institute of
170*86d7f5d3SJohn MarinoElectrical and Electronics Engineers, Inc and The Open Group.
171*86d7f5d3SJohn MarinoIn the
172*86d7f5d3SJohn Marinoevent of any discrepancy between this version and the original IEEE and
173*86d7f5d3SJohn MarinoThe Open Group Standard, the original IEEE and The Open Group Standard
174*86d7f5d3SJohn Marinois the referee document.
175*86d7f5d3SJohn MarinoThe original Standard can be obtained online at
176*86d7f5d3SJohn Marinohttp://www.opengroup.org/unix/online.html .
177