Updated: April 19, 2023 |
Send a message to a message queue
#include <mqueue.h> #include <time.h> int mq_timedsend( mqd_t mqdes, const char * msg_ptr, size_t msg_len, unsigned int msg_prio, const struct timespec * abs_timeout ); int mq_timedsend_monotonic( mqd_t mqdes, const char * msg_ptr, size_t msg_len, unsigned int msg_prio, const struct timespec * abs_timeout );
The mq_timedsend() function puts a message of size msg_len and pointed to by msg_ptr into the queue indicated by mqdes. The new message has a priority of msg_prio. The mq_timedsend_monotonic() function is a QNX Neutrino extension; it's similar to mq_timedsend(), but it uses CLOCK_MONOTONIC, so the timeout isn't affected by changes to the system time.
If you want to choose the clock against which the timeout is measured, you can instead use mq_clocksend(), which is similar to mq_timedsend() and mq_timedsend_monotonic() and differs only because of its clock parameter (clk). Choosing the clock prevents the timeout from being affected by changes to the system time.
The queue maintained is in priority order, and in FIFO order within the same priority.
If the number of elements on the specified queue is equal to its mq_maxmsg, and O_NONBLOCK wasn't set (in the oflag argument to mq_open()), the call to mq_timedsend() blocks. It becomes unblocked when there's room on the queue to send the given message. If more than one mq_timedsend() is blocked on a given queue, and space becomes available in that queue to send, then the mq_timedsend() with the highest priority message is unblocked.
-1 if an error occurred (errno is set). Any other value indicates success.
See the example for mq_open().
mq_timedsend() is POSIX 1003.1; mq_timedsend_monotonic() is QNX Neutrino
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |