mq_receive - receive a message from a message queue
#include <mqueue.h>
mq_receive() is used to receive the oldest of the highest priority message(s) from the message queue specified by mqdes . If the size of the buffer in bytes, specified by msg_len , is less than the mq_msgsize attribute of the message queue, the function fails and returns an error. Otherwise, the selected message is removed from the queue and copied to the buffer pointed to by msg_ptr.
If msg_prio is not NULL, the priority of the selected message is stored in the location referenced by msg_prio .
If the specified message queue is empty and O_NONBLOCK is not set in the message queue description associated with mqdes , (see mq_open() and mq_setattr() ), mq_receive() blocks, waiting until a message is enqueued on the message queue. If more than one thread is waiting to receive a message when a message arrives at an empty queue, then the thread of highest priority that has been waiting the longest is selected to receive the message. If the specified message queue is empty and O_NONBLOCK is set in the message queue description associated with mqdes , no message is removed from the queue, and mq_receive() returns an error.
Upon successful completion, mq_receive() returns the length of the selected message in bytes and the message will have been removed from the queue. Otherwise, no message is removed from the queue, the function returns a value of -1 , and sets errno to indicate the error condition.
mq_open(), mq_send(), mq_setattr(), mq_timedreceive()