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