cc [ flag... ] file... -lrt [ library... ] #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 adds the message pointed to by the argument msg_ptr to the message queue specified by mqdes. The msg_len argument specifies the length of the message in bytes pointed to by msg_ptr. The value of msg_len is less than or equal to the mq_msgsize attribute of the message queue, or mq_send() fails.
If the specified message queue is not full, mq_send() behaves as if the message is inserted into the message queue at the position indicated by the msg_prio argument. A message with a larger numeric value of msg_prio is inserted before messages with lower values of msg_prio. A message will be inserted after other messages in the queue, if any, with equal msg_prio. The value of msg_prio must be greater than zero and less than or equal to MQ_PRIO_MAX.
If the specified message queue is full and O_NONBLOCK is not set in the message queue description associated with mqdes (see mq_open(3RT) and mq_setattr(3RT)), mq_send() blocks until space becomes available to enqueue the message, or until mq_send() is interrupted by a signal. If more than one thread is waiting to send when space becomes available in the message queue, then the thread of the highest priority which has been waiting the longest is unblocked to send its message. Otherwise, it is unspecified which waiting thread is unblocked. If the specified message queue is full and O_NONBLOCK is set in the message queue description associated with mqdes, the message is not queued and mq_send() returns an error.
Upon successful completion, mq_send() returns 0; otherwise, no message is enqueued, the function returns -1, and errno is set to indicate the error.
The mq_send() function will fail if:
The O_NONBLOCK flag is set in the message queue description associated with mqdes, and the specified message queue is full.
The mqdes argument is not a valid message queue descriptor open for writing.
A signal interrupted the call to mq_send()
The value of msg_prio was outside the valid range.
The specified message length, msg_len, exceeds the message size attribute of the message queue.
The mq_send() function is not supported by the system.
See attributes(5) for descriptions of the following attributes:
|ATTRIBUTE TYPE||ATTRIBUTE VALUE|
Solaris 2.6 was the first release to support the Asynchronous Input and Output option. Prior to this release, this function always returned -1 and set errno to ENOSYS.