[Previous] [Contents] [Next]

mq_timedsend()

Send a message to a message queue

Synopsis:

#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 );

Library:

libc

Description:

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.


Note: The time contained in the abs_timeout argument specifies the absolute time (not the relative time to the current time) to wait before it stops trying to send messages.

The queue maintained is in priority order (priorities may range from 0 to MQ_PRIO_MAX), and in FIFO order within the same priority.

If the number of elements on the specified queue is equal to its mq_maxmsg, and neither O_NONBLOCK (in oflag of mq_open()) nor MQ_NONBLOCK (in the queue's mq_flags) has been set, 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.

Calling write() with mqdes is analogous to calling mq_timedsend() with a msg_prio of 0.

Returns:

-1
An error occurred (errno is set).
Any other value
Success.

Errors:

EAGAIN
The O_NONBLOCK flag is set when opening the queue, or the MQ_NONBLOCK flag is set in its attributes, and the specified queue is full.
EBADF
The mqdes argument doesn't represent a valid message queue descriptor, or mqdes isn't opened for writing.
EINTR
The call was interrupted by a signal.
EINVAL
One of the following is true:
EMSGSIZE
The msg_len argument is greater than the msgsize associated with the specified queue.
ETIMEDOUT
The timeout value was exceeded.

Examples:

See the example for mq_timedreceive().

Classification:

POSIX 1003.1d (draft)

Safety:
Cancellation point Yes
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

mq_close(), mq_open(), mq_receive()


[Previous] [Contents] [Next]