put a message into a message queue


#include <mqueue.h>
int mq_send( mqd_t mqdes, 
             const char *msg_ptr, 
             size_t msg_len, 
             unsigned int msg_prio );


The mq_send() function puts a message of size msg_len, pointed to by msg_ptr into the queue indicated by mq_des. The new message has a priority of msg_prio.

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

If the QNX extension MQ_PRIO_RESTRICT has been set for the queue, then an attempt to send a message at a msg_prio higher than the priority of the sending process results in an error, and errno is set to EINVAL. If the QNX extension MQ_PRIO_BOOST has been set, and msg_prio is 0, then the priority of the message is boosted to that of the calling process.

If the number of elements on the specified queue is equal to its mq_maxmsg (and mq_maxmsg doesn't equal 0), 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_send() blocks. It becomes unblocked when there is room on the queue to send the given message. If more than one mq_send() is blocked on a given queue, and space becomes available in that queue to send, then the mq_send() with the highest priority message is unblocked.

Calling write() on a file descriptor that represents a message queue is analogous to calling mq_send() with a msg_prio of 0.


An error occurred. Check the value of errno.


The O_NONBLOCK flag was set when opening the queue, or the MQ_NONBLOCK flag was set in its attributes, and the specified queue is full.
mq_des doesn't represent a valid message queue descriptor, or mq_des wasn't opened for writing.
The call was interrupted by a signal.
This value indicates one of the following:
The msg_len is greater than the msgsize associated with the specified queue.


POSIX 1003.4

Interrupt handler No
Signal handler Yes, but modifies errno
Thread Yes


In order to use the mq_... functions, you must:

See also:

errno, mq_close(), mq_getattr(), mq_notify(), mq_open(), mq_receive(), mq_setattr(), mq_unlink()

chapter on POSIX.4 message queues