]>
Commit | Line | Data |
---|---|---|
80a99f39 | 1 | '\" t |
c11b1abf | 2 | .\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com> |
80a99f39 | 3 | .\" |
93015253 | 4 | .\" %%%LICENSE_START(VERBATIM) |
80a99f39 MK |
5 | .\" Permission is granted to make and distribute verbatim copies of this |
6 | .\" manual provided the copyright notice and this permission notice are | |
7 | .\" preserved on all copies. | |
8 | .\" | |
9 | .\" Permission is granted to copy and distribute modified versions of this | |
10 | .\" manual under the conditions for verbatim copying, provided that the | |
11 | .\" entire resulting derived work is distributed under the terms of a | |
12 | .\" permission notice identical to this one. | |
c13182ef | 13 | .\" |
80a99f39 MK |
14 | .\" Since the Linux kernel and libraries are constantly changing, this |
15 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
16 | .\" responsibility for errors or omissions, or for damages resulting from | |
10d76543 MK |
17 | .\" the use of the information contained herein. The author(s) may not |
18 | .\" have taken the same level of care in the production of this manual, | |
19 | .\" which is licensed free of charge, as they might when working | |
20 | .\" professionally. | |
c13182ef | 21 | .\" |
80a99f39 MK |
22 | .\" Formatted or processed versions of this manual, if unaccompanied by |
23 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 24 | .\" %%%LICENSE_END |
80a99f39 | 25 | .\" |
4b8c67d9 | 26 | .TH MQ_RECEIVE 3 2017-09-15 "Linux" "Linux Programmer's Manual" |
80a99f39 MK |
27 | .SH NAME |
28 | mq_receive, mq_timedreceive \- receive a message from a message queue | |
29 | .SH SYNOPSIS | |
30 | .nf | |
31 | .B #include <mqueue.h> | |
68e4db0a | 32 | .PP |
36e212c6 | 33 | .BI "ssize_t mq_receive(mqd_t " mqdes ", char *" msg_ptr , |
c1234a3b | 34 | .BI " size_t " msg_len ", unsigned int *" msg_prio ); |
68e4db0a | 35 | .PP |
80a99f39 MK |
36 | .B #include <time.h> |
37 | .B #include <mqueue.h> | |
68e4db0a | 38 | .PP |
36e212c6 | 39 | .BI "ssize_t mq_timedreceive(mqd_t " mqdes ", char *" msg_ptr , |
c1234a3b | 40 | .BI " size_t " msg_len ", unsigned int *" msg_prio , |
36e212c6 | 41 | .BI " const struct timespec *" abs_timeout ); |
80a99f39 | 42 | .fi |
68e4db0a | 43 | .PP |
1b2d3fca | 44 | Link with \fI\-lrt\fP. |
68e4db0a | 45 | .PP |
9a30939e MK |
46 | .ad l |
47 | .in -4n | |
48 | Feature Test Macro Requirements for glibc (see | |
49 | .BR feature_test_macros (7)): | |
50 | .in | |
68e4db0a | 51 | .PP |
9a30939e MK |
52 | .BR mq_timedreceive (): |
53 | .RS 4 | |
a446ac0c | 54 | _POSIX_C_SOURCE\ >=\ 200112L |
9a30939e MK |
55 | .RE |
56 | .ad | |
80a99f39 MK |
57 | .SH DESCRIPTION |
58 | .BR mq_receive () | |
c13182ef | 59 | removes the oldest message with the highest priority from |
d9cb0d7d | 60 | the message queue referred to by the message queue descriptor |
80a99f39 MK |
61 | .IR mqdes , |
62 | and places it in the buffer pointed to by | |
63 | .IR msg_ptr . | |
64 | The | |
65 | .I msg_len | |
66 | argument specifies the size of the buffer pointed to by | |
67 | .IR msg_ptr ; | |
61a70efc | 68 | this must be greater than or equal to the |
80a99f39 | 69 | .I mq_msgsize |
c13182ef | 70 | attribute of the queue (see |
80a99f39 MK |
71 | .BR mq_getattr (3)). |
72 | If | |
37f02e32 | 73 | .I msg_prio |
c13182ef | 74 | is not NULL, then the buffer to which it points is used |
80a99f39 | 75 | to return the priority associated with the received message. |
847e0d88 | 76 | .PP |
80a99f39 MK |
77 | If the queue is empty, then, by default, |
78 | .BR mq_receive () | |
79 | blocks until a message becomes available, | |
80 | or the call is interrupted by a signal handler. | |
c13182ef | 81 | If the |
80a99f39 MK |
82 | .B O_NONBLOCK |
83 | flag is enabled for the message queue description, | |
84 | then the call instead fails immediately with the error | |
85 | .BR EAGAIN . | |
847e0d88 | 86 | .PP |
80a99f39 MK |
87 | .BR mq_timedreceive () |
88 | behaves just like | |
89 | .BR mq_receive (), | |
90 | except that if the queue is empty and the | |
91 | .B O_NONBLOCK | |
92 | flag is not enabled for the message queue description, then | |
93 | .I abs_timeout | |
3824cf5b MK |
94 | points to a structure which specifies how long the call will block. |
95 | This value is an absolute timeout in seconds and nanoseconds | |
96 | since the Epoch, 1970-01-01 00:00:00 +0000 (UTC), | |
80a99f39 | 97 | specified in the following structure: |
51f5698d | 98 | .PP |
bd191423 | 99 | .in +4n |
b8302363 | 100 | .EX |
80a99f39 MK |
101 | struct timespec { |
102 | time_t tv_sec; /* seconds */ | |
103 | long tv_nsec; /* nanoseconds */ | |
104 | }; | |
b8302363 | 105 | .EE |
bd191423 | 106 | .in |
bdd915e2 | 107 | .PP |
80a99f39 MK |
108 | If no message is available, |
109 | and the timeout has already expired by the time of the call, | |
110 | .BR mq_timedreceive () | |
111 | returns immediately. | |
112 | .SH RETURN VALUE | |
113 | On success, | |
114 | .BR mq_receive () | |
115 | and | |
116 | .BR mq_timedreceive () | |
117 | return the number of bytes in the received message; | |
118 | on error, \-1 is returned, with | |
c13182ef | 119 | .I errno |
80a99f39 MK |
120 | set to indicate the error. |
121 | .SH ERRORS | |
122 | .TP | |
123 | .B EAGAIN | |
124 | The queue was empty, and the | |
125 | .B O_NONBLOCK | |
126 | flag was set for the message queue description referred to by | |
127 | .IR mqdes . | |
128 | .TP | |
129 | .B EBADF | |
e186d0ca | 130 | The descriptor specified in |
80a99f39 | 131 | .I mqdes |
e1ca8255 | 132 | was invalid or not opened for reading. |
80a99f39 | 133 | .TP |
80a99f39 | 134 | .B EINTR |
01538d0d MK |
135 | The call was interrupted by a signal handler; see |
136 | .BR signal (7). | |
80a99f39 MK |
137 | .TP |
138 | .B EINVAL | |
c13182ef | 139 | The call would have blocked, and |
80a99f39 MK |
140 | .I abs_timeout |
141 | was invalid, either because | |
142 | .I tv_sec | |
143 | was less than zero, or because | |
c13182ef | 144 | .I tv_nsec |
80a99f39 MK |
145 | was less than zero or greater than 1000 million. |
146 | .TP | |
eab64696 | 147 | .B EMSGSIZE |
0daa9e92 | 148 | .I msg_len |
eab64696 MK |
149 | was less than the |
150 | .I mq_msgsize | |
151 | attribute of the message queue. | |
152 | .TP | |
80a99f39 MK |
153 | .B ETIMEDOUT |
154 | The call timed out before a message could be transferred. | |
db17fccd | 155 | .SH ATTRIBUTES |
dd975639 PH |
156 | For an explanation of the terms used in this section, see |
157 | .BR attributes (7). | |
158 | .TS | |
159 | allbox; | |
160 | lbw31 lb lb | |
161 | l l l. | |
162 | Interface Attribute Value | |
163 | T{ | |
164 | .BR mq_receive (), | |
db17fccd | 165 | .BR mq_timedreceive () |
dd975639 PH |
166 | T} Thread safety MT-Safe |
167 | .TE | |
80a99f39 | 168 | .SH CONFORMING TO |
8096c228 | 169 | POSIX.1-2001, POSIX.1-2008. |
c89e428b MK |
170 | .SH NOTES |
171 | On Linux, | |
172 | .BR mq_timedreceive () | |
173 | is a system call, and | |
174 | .BR mq_receive () | |
175 | is a library function layered on top of that system call. | |
47297adb | 176 | .SH SEE ALSO |
80a99f39 MK |
177 | .BR mq_close (3), |
178 | .BR mq_getattr (3), | |
179 | .BR mq_notify (3), | |
180 | .BR mq_open (3), | |
181 | .BR mq_send (3), | |
182 | .BR mq_unlink (3), | |
1d7c4d16 MK |
183 | .BR mq_overview (7), |
184 | .BR time (7) |