1mq_receive(3C) Standard C Library Functions mq_receive(3C)
2
3
4
6 mq_receive, mq_timedreceive, mq_reltimedreceive_np - receive a message
7 from a message queue
8
10 #include <mqueue.h>
11
12 ssize_t mq_receive(mqd_t mqdes, char *msg_ptr, size_t msg_len,
13 unsigned *msg_prio);
14
15
16 #include <mqueue.h>
17 #include <time.h>
18
19 ssize_t mq_timedreceive(mqd_t mqdes, char *restrict msg_ptr,
20 size_t msg_len, unsigned *restrict msg_prio,
21 const struct timespec *restrict abs_timeout);
22
23
24 ssize_t mq_reltimedreceive_np(mqd_t mqdes,
25 char *restrict msg_ptr, size_t msg_len,
26 unsigned *restrict msg_prio,
27 const struct timespec *restrict rel_timeout);
28
29
31 The mq_receive() function receives the oldest of the highest priority
32 message(s) from the message queue specified by mqdes. If the size of
33 the buffer in bytes, specified by msg_len, is less than the mq_msgsize
34 member of the message queue, the function fails and returns an error.
35 Otherwise, the selected message is removed from the queue and copied to
36 the buffer pointed to by msg_ptr.
37
38
39 If the value of msg_len is greater than {SSIZE_MAX}, the result is
40 implementation-defined.
41
42
43 If msg_prio is not NULL, the priority of the selected message is stored
44 in the location referenced by msg_prio.
45
46
47 If the specified message queue is empty and O_NONBLOCK is not set in
48 the message queue description associated with mqdes, (see mq_open(3C)
49 and mq_setattr(3C)), mq_receive() blocks, waiting until a message is
50 enqueued on the message queue, or until mq_receive() is interrupted by
51 a signal. If more than one process (or thread) is waiting to receive a
52 message when a message arrives at an empty queue, then the process of
53 highest priority that has been waiting the longest is selected to
54 receive the message. If the specified message queue is empty and
55 O_NONBLOCK is set in the message queue description associated with
56 mqdes, no message is removed from the queue, and mq_receive() returns
57 an error.
58
59
60 The mq_timedreceive() function receives the oldest of the highest pri‐
61 ority messages from the message queue specified by mqdes as described
62 for the mq_receive() function. However, if O_NONBLOCK was not specified
63 when the message queue was opened with the mq_open(3C) function, and no
64 message exists on the queue to satisfy the receive, the wait for such a
65 message is terminated when the specified timeout expires. If O_NONBLOCK
66 is set, this function is equivalent to mq_receive().
67
68
69 The mq_reltimedreceive_np() function is identical to the mq_time‐
70 dreceive() function, except that the timeout is specified as a relative
71 time interval.
72
73
74 For mq_timedreceive(), the timeout expires when the absolute time spec‐
75 ified by abs_timeout passes, as measured by the CLOCK_REALTIME clock
76 (that is, when the value of that clock equals or exceeds abs_timeout),
77 or if the absolute time specified by abs_timeout has already been
78 passed at the time of the call.
79
80
81 For mq_reltimedreceive_np(), the timeout expires when the time interval
82 specified by rel_timeout passes, as measured by the CLOCK_REALTIME
83 clock, or if the time interval specified by rel_timeout is negative at
84 the time of the call.
85
86
87 The resolution of the timeout is the resolution of the CLOCK_REALTIME
88 clock. The timespec argument is defined in the <time.h> header.
89
90
91 Under no circumstance does the operation fail with a timeout if a mes‐
92 sage can be removed from the message queue immediately. The validity of
93 the timeout parameter need not be checked if a message can be removed
94 from the message queue immediately.
95
97 Upon successful completion, mq_receive(), mq_timedreceive(), and
98 mq_reltimedreceive_np() return the length of the selected message in
99 bytes and the message is removed from the queue. Otherwise, no message
100 is removed from the queue, the functions return a value of −1, and sets
101 errno to indicate the error condition.
102
104 The mq_receive(), mq_timedreceive(), and mq_reltimedreceive_np() func‐
105 tions will fail if:
106
107 EAGAIN O_NONBLOCK was set in the message description associated
108 with mqdes, and the specified message queue is empty.
109
110
111 EBADF The mqdes argument is not a valid message queue descriptor
112 open for reading.
113
114
115 EINTR The function was interrupted by a signal.
116
117
118 EINVAL The process or thread would have blocked, and the timeout
119 parameter specified a nanoseconds field value less than
120 zero or greater than or equal to 1,000 million.
121
122
123 EMSGSIZE The specified message buffer size, msg_len, is less than
124 the message size member of the message queue.
125
126
127 ETIMEDOUT The O_NONBLOCK flag was not set when the message queue was
128 opened, but no message arrived on the queue before the
129 specified timeout expired.
130
131
132
133 The mq_receive(), mq_timedreceive(), and mq_reltimedreceive_np() func‐
134 tions may fail if:
135
136 EBADMSG A data corruption problem with the message has been
137 detected.
138
139
141 See attributes(5) for descriptions of the following attributes:
142
143
144
145
146 ┌─────────────────────────────┬─────────────────────────────┐
147 │ATTRIBUTE TYPE │ATTRIBUTE VALUE │
148 ├─────────────────────────────┼─────────────────────────────┤
149 │Interface Stability │Committed │
150 ├─────────────────────────────┼─────────────────────────────┤
151 │MT-Level │MT-Safe │
152 ├─────────────────────────────┼─────────────────────────────┤
153 │Standard │See below. │
154 └─────────────────────────────┴─────────────────────────────┘
155
156
157 For mq_receive() and mq_timedreceive(). see standards(5).
158
160 mqueue.h(3HEAD), mq_open(3C), mq_send(3C), mq_setattr(3C),
161 attributes(5), standards(5)
162
163
164
165SunOS 5.11 5 Feb 2008 mq_receive(3C)