Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved.
Copyright 1989 AT&T
Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved.
Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
http://www.opengroup.org/bookstore/.
The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
This notice shall appear on any product containing this material.
The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
#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);
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(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.
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.
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.
The mqdes argument is not a valid message queue descriptor open for writing.
A signal interrupted the function call.
The value of msg_prio was outside the valid range.
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.
The specified message length, msg_len, exceeds the message size attribute of the message queue.
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.
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).
sysconf(3C), mqueue.h(3HEAD), mq_open(3C), mq_receive(3C), mq_setattr(3C), attributes(5), standards(5)