MQ_SEND(3C) Standard C Library Functions MQ_SEND(3C)


NAME


mq_send, mq_timedsend, mq_reltimedsend_np - send a message to a message
queue

SYNOPSIS


#include <mqueue.h>

int mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_len,
unsigned msg_prio);


#include <mqueue.h>
#include <time.h>

int mq_timedsend(mqd_t mqdes, const char *msg_ptr,
size_t msg_len, unsigned msg_prio,
const struct timespec *restrict abs_timeout);


int mq_reltimedsend_np(mqd_t mqdes, const char *msg_ptr,
size_t msg_len, unsigned msg_prio,
const struct timespec *restrict rel_timeout);


DESCRIPTION


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 range from zero to MQ_PRIO_MAX - 1.


If the specified message queue is full and O_NONBLOCK is not set in the
message queue description associated with mqdes (see mq_open(3C) and
mq_setattr(3C)), 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.


The mq_timedsend() function adds a message to the message queue specified
by mqdes in the manner defined for the mq_send() function. However, if
the specified message queue is full and O_NONBLOCK is not set in the
message queue description associated with mqdes, the wait for sufficient
room in the queue is terminated when the specified timeout expires. If
O_NONBLOCK is set in the message queue description, this function is
equivalent to mq_send().


The mq_reltimedsend_np() function is identical to the mq_timedsend()
function, except that the timeout is specified as a relative time
interval.


For mq_timedsend(), the timeout expires when the absolute time specified
by abs_timeout passes, as measured by the CLOCK_REALTIME clock (that is,
when the value of that clock equals or exceeds abs_timeout), or if the
absolute time specified by abs_timeout has already been passed at the
time of the call.


For mq_reltimedsend_np(), the timeout expires when the time interval
specified by rel_timeout passes, as measured by the CLOCK_REALTIME clock,
or if the time interval specified by rel_timeout is negative at the time
of the call.


The resolution of the timeout is the resolution of the CLOCK_REALTIME
clock. The timespec argument is defined in the <time.h> header.


Under no circumstance does the operation fail with a timeout if there is
sufficient room in the queue to add the message immediately. The validity
of the timeout parameter need not be checked when there is sufficient
room in the queue.

RETURN VALUES


Upon successful completion, mq_send(), mq_timedsend(), and
mq_reltimedsend_np() return 0. Otherwise, no message is enqueued, the
functions return -1, and errno is set to indicate the error.

ERRORS


The mq_send(), mq_timedsend(), and mq_reltimedsend_np() functions will
fail if:

EAGAIN
The O_NONBLOCK flag is set in the message queue description
associated with mqdes, and the specified message queue is
full.


EBADF
The mqdes argument is not a valid message queue descriptor
open for writing.


EINTR
A signal interrupted the function call.


EINVAL
The value of msg_prio was outside the valid range.


EINVAL
The process or thread would have blocked, and the timeout
parameter specified a nanoseconds field value less than zero
or greater than or equal to 1,000 million.


EMSGSIZE
The specified message length, msg_len, exceeds the message
size attribute of the message queue.


ETIMEDOUT
The O_NONBLOCK flag was not set when the message queue was
opened, but the timeout expired before the message could be
added to the queue.


ATTRIBUTES


See attributes(5) for descriptions of the following attributes:


+--------------------+-----------------+
|ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+--------------------+-----------------+
|Interface Stability | Committed |
+--------------------+-----------------+
|MT-Level | MT-Safe |
+--------------------+-----------------+
|Standard | See below. |
+--------------------+-----------------+


For mq_send() and mq_timedsend(), see standards(5).

SEE ALSO


sysconf(3C), mqueue.h(3HEAD), mq_open(3C), mq_receive(3C),
mq_setattr(3C), attributes(5), standards(5)


October 23, 2014 MQ_SEND(3C)