tzfile.5, tzselect.8: sync from tzdb upstream
[man-pages.git] / man3 / mq_receive.3
blob6be6223582c24fd5d1d38066f939ffe02cb2c379
1 '\" t
2 .\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .TH mq_receive 3 (date) "Linux man-pages (unreleased)"
7 .SH NAME
8 mq_receive, mq_timedreceive \- receive a message from a message queue
9 .SH LIBRARY
10 Real-time library
11 .RI ( librt ", " \-lrt )
12 .SH SYNOPSIS
13 .nf
14 .B #include <mqueue.h>
15 .PP
16 .BI "ssize_t mq_receive(mqd_t " mqdes ", char " msg_ptr [. msg_len ],
17 .BI "                   size_t " msg_len ", unsigned int *" msg_prio );
18 .PP
19 .B #include <time.h>
20 .B #include <mqueue.h>
21 .PP
22 .BI "ssize_t mq_timedreceive(mqd_t " mqdes ", \
23 char *restrict " msg_ptr [. msg_len ],
24 .BI "                   size_t " msg_len ", unsigned int *restrict " msg_prio ,
25 .BI "                   const struct timespec *restrict " abs_timeout );
26 .fi
27 .PP
28 .ad l
29 .RS -4
30 Feature Test Macro Requirements for glibc (see
31 .BR feature_test_macros (7)):
32 .RE
33 .PP
34 .BR mq_timedreceive ():
35 .nf
36     _POSIX_C_SOURCE >= 200112L
37 .fi
38 .SH DESCRIPTION
39 .BR mq_receive ()
40 removes the oldest message with the highest priority from
41 the message queue referred to by the message queue descriptor
42 .IR mqdes ,
43 and places it in the buffer pointed to by
44 .IR msg_ptr .
45 The
46 .I msg_len
47 argument specifies the size of the buffer pointed to by
48 .IR msg_ptr ;
49 this must be greater than or equal to the
50 .I mq_msgsize
51 attribute of the queue (see
52 .BR mq_getattr (3)).
54 .I msg_prio
55 is not NULL, then the buffer to which it points is used
56 to return the priority associated with the received message.
57 .PP
58 If the queue is empty, then, by default,
59 .BR mq_receive ()
60 blocks until a message becomes available,
61 or the call is interrupted by a signal handler.
62 If the
63 .B O_NONBLOCK
64 flag is enabled for the message queue description,
65 then the call instead fails immediately with the error
66 .BR EAGAIN .
67 .PP
68 .BR mq_timedreceive ()
69 behaves just like
70 .BR mq_receive (),
71 except that if the queue is empty and the
72 .B O_NONBLOCK
73 flag is not enabled for the message queue description, then
74 .I abs_timeout
75 points to a structure which specifies how long the call will block.
76 This value is an absolute timeout in seconds and nanoseconds
77 since the Epoch, 1970-01-01 00:00:00 +0000 (UTC),
78 specified in a
79 .BR timespec (3)
80 structure.
81 .PP
82 If no message is available,
83 and the timeout has already expired by the time of the call,
84 .BR mq_timedreceive ()
85 returns immediately.
86 .SH RETURN VALUE
87 On success,
88 .BR mq_receive ()
89 and
90 .BR mq_timedreceive ()
91 return the number of bytes in the received message;
92 on error, \-1 is returned, with
93 .I errno
94 set to indicate the error.
95 .SH ERRORS
96 .TP
97 .B EAGAIN
98 The queue was empty, and the
99 .B O_NONBLOCK
100 flag was set for the message queue description referred to by
101 .IR mqdes .
103 .B EBADF
104 The descriptor specified in
105 .I mqdes
106 was invalid or not opened for reading.
108 .B EINTR
109 The call was interrupted by a signal handler; see
110 .BR signal (7).
112 .B EINVAL
113 The call would have blocked, and
114 .I abs_timeout
115 was invalid, either because
116 .I tv_sec
117 was less than zero, or because
118 .I tv_nsec
119 was less than zero or greater than 1000 million.
121 .B EMSGSIZE
122 .I msg_len
123 was less than the
124 .I mq_msgsize
125 attribute of the message queue.
127 .B ETIMEDOUT
128 The call timed out before a message could be transferred.
129 .SH ATTRIBUTES
130 For an explanation of the terms used in this section, see
131 .BR attributes (7).
132 .ad l
135 allbox;
136 lbx lb lb
137 l l l.
138 Interface       Attribute       Value
140 .BR mq_receive (),
141 .BR mq_timedreceive ()
142 T}      Thread safety   MT-Safe
146 .sp 1
147 .SH STANDARDS
148 POSIX.1-2001, POSIX.1-2008.
149 .SH NOTES
150 On Linux,
151 .BR mq_timedreceive ()
152 is a system call, and
153 .BR mq_receive ()
154 is a library function layered on top of that system call.
155 .SH SEE ALSO
156 .BR mq_close (3),
157 .BR mq_getattr (3),
158 .BR mq_notify (3),
159 .BR mq_open (3),
160 .BR mq_send (3),
161 .BR mq_unlink (3),
162 .BR timespec (3),
163 .BR mq_overview (7),
164 .BR time (7)