![]() |
![]() |
![]() |
![]() |
![]() |
This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs. |
Receive a message from a message queue
#include <mqueue.h>
#include <time.h>
ssize_t mq_timedreceive(
mqd_t mqdes,
char * msg_ptr,
size_t msg_len,
unsigned int * msg_prio,
const struct timespec * abs_timeout );
Use the -l c option to qcc to link against this library. This library is usually included automatically.
Use the -l mq option to qcc to link against this library.
The mq_timedreceive() function receives the oldest of the highest priority messages in the queue specified by mqdes.
![]() |
Neutrino supports two implementations of message queues: a traditional implementation, and an alternate one that uses asynchronous messages. For more information, see the entry for mq and mqueue in the Utilities Reference. |
If you call mq_timedreceive() with a msg_len of anything other than the mq_msgsize of the specified queue, then mq_timedreceive() returns an error, and errno is set to EINVAL.
If there are no messages on the queue specified, and O_NONBLOCK isn't set in oflag during mq_open(), then the mq_timedreceive() call blocks. If multiple mq_timedreceive() 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_timedreceive() with a NULL msg_prio.
The size of the message removed from the queue, or -1 if an error occurred (no message is removed from the queue, and errno is set).
Specify an absolute timeout of 1 second:
struct timespec tm;
clock_gettime(CLOCK_REALTIME, &tm);
tm.tv_sec += 1;
if( 0 > mq_timedreceive( fd, buf, 4096, NULL, t ) ) {
...
}
| Safety: | |
|---|---|
| Cancellation point | Yes |
| Interrupt handler | No |
| Signal handler | Yes |
| Thread | Yes |
mq_close(), mq_open(), mq_receive(), mq_send(), mq_timedsend(), timespec
mq, mqueue in the Utilities Reference
![]() |
![]() |
![]() |
![]() |