1mq_receive(3) Library Functions Manual mq_receive(3)
2
3
4
6 mq_receive, mq_timedreceive - receive a message from a message queue
7
9 Real-time library (librt, -lrt)
10
12 #include <mqueue.h>
13
14 ssize_t mq_receive(mqd_t mqdes, char msg_ptr[.msg_len],
15 size_t msg_len, unsigned int *msg_prio);
16
17 #include <time.h>
18 #include <mqueue.h>
19
20 ssize_t mq_timedreceive(mqd_t mqdes, char *restrict msg_ptr[.msg_len],
21 size_t msg_len, unsigned int *restrict msg_prio,
22 const struct timespec *restrict abs_timeout);
23
24 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
25
26 mq_timedreceive():
27 _POSIX_C_SOURCE >= 200112L
28
30 mq_receive() removes the oldest message with the highest priority from
31 the message queue referred to by the message queue descriptor mqdes,
32 and places it in the buffer pointed to by msg_ptr. The msg_len argu‐
33 ment specifies the size of the buffer pointed to by msg_ptr; this must
34 be greater than or equal to the mq_msgsize attribute of the queue (see
35 mq_getattr(3)). If msg_prio is not NULL, then the buffer to which it
36 points is used to return the priority associated with the received mes‐
37 sage.
38
39 If the queue is empty, then, by default, mq_receive() blocks until a
40 message becomes available, or the call is interrupted by a signal han‐
41 dler. If the O_NONBLOCK flag is enabled for the message queue descrip‐
42 tion, then the call instead fails immediately with the error EAGAIN.
43
44 mq_timedreceive() behaves just like mq_receive(), except that if the
45 queue is empty and the O_NONBLOCK flag is not enabled for the message
46 queue description, then abs_timeout points to a structure which speci‐
47 fies how long the call will block. This value is an absolute timeout
48 in seconds and nanoseconds since the Epoch, 1970-01-01 00:00:00 +0000
49 (UTC), specified in a timespec(3) structure.
50
51 If no message is available, and the timeout has already expired by the
52 time of the call, mq_timedreceive() returns immediately.
53
55 On success, mq_receive() and mq_timedreceive() return the number of
56 bytes in the received message; on error, -1 is returned, with errno set
57 to indicate the error.
58
60 EAGAIN The queue was empty, and the O_NONBLOCK flag was set for the
61 message queue description referred to by mqdes.
62
63 EBADF The descriptor specified in mqdes was invalid or not opened for
64 reading.
65
66 EINTR The call was interrupted by a signal handler; see signal(7).
67
68 EINVAL The call would have blocked, and abs_timeout was invalid, either
69 because tv_sec was less than zero, or because tv_nsec was less
70 than zero or greater than 1000 million.
71
72 EMSGSIZE
73 msg_len was less than the mq_msgsize attribute of the message
74 queue.
75
76 ETIMEDOUT
77 The call timed out before a message could be transferred.
78
80 For an explanation of the terms used in this section, see at‐
81 tributes(7).
82
83 ┌────────────────────────────────────────────┬───────────────┬─────────┐
84 │Interface │ Attribute │ Value │
85 ├────────────────────────────────────────────┼───────────────┼─────────┤
86 │mq_receive(), mq_timedreceive() │ Thread safety │ MT-Safe │
87 └────────────────────────────────────────────┴───────────────┴─────────┘
88
90 On Linux, mq_timedreceive() is a system call, and mq_receive() is a li‐
91 brary function layered on top of that system call.
92
94 POSIX.1-2008.
95
97 POSIX.1-2001.
98
100 mq_close(3), mq_getattr(3), mq_notify(3), mq_open(3), mq_send(3),
101 mq_unlink(3), timespec(3), mq_overview(7), time(7)
102
103
104
105Linux man-pages 6.04 2023-03-30 mq_receive(3)