Updated: April 19, 2023 |
Receive a message from a queue
#include <mqueue.h> ssize_t mq_receive( mqd_t mqdes, char* msg_ptr, size_t msg_len, unsigned int* msg_prio );
The mq_receive() function is used to receive the oldest of the highest priority messages in the queue specified by mqdes. The priority of the message received is put in the location pointed to by msg_prio, the data itself in the location pointed to by msg_ptr, and the size received is returned.
If you call mq_receive() with a msg_len that's less than the mq_msgsize of the specified queue, then mq_receive() returns an error and sets errno to EMSGSIZE.
If there are no messages on the queue specified, and O_NONBLOCK wasn't set (in the oflag argument to mq_open()), then the mq_receive() call blocks. If multiple mq_receive() calls are blocked on a single queue, then they're unblocked in FIFO order as messages arrive.
In the traditional (mqueue) implementation, calling read() with mqdes is analogous to calling mq_receive() with a NULL msg_prio.
The size of the message removed from the queue. If the call fails, -1 is returned as the size, no message is removed from the queue, and errno is set.
See the example for mq_open().
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | No |
Thread | Yes |