.\" .\" 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 SunOS 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] .\" .\" .\" Copyright 1989 AT&T .\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved. .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved. .\" Copyright (c) 2014, Ryan Zezeski. .\" .TH MQ_SEND 3C "Oct 23, 2014" .SH NAME mq_send, mq_timedsend, mq_reltimedsend_np \- send a message to a message queue .SH SYNOPSIS .LP .nf #include \fBint\fR \fBmq_send\fR(\fBmqd_t\fR \fImqdes\fR, \fBconst char *\fR\fImsg_ptr\fR, \fBsize_t\fR \fImsg_len\fR, \fBunsigned\fR \fImsg_prio\fR); .fi .LP .nf #include #include \fBint\fR \fBmq_timedsend\fR(\fBmqd_t\fR \fImqdes\fR, \fBconst char *\fR\fImsg_ptr\fR, \fBsize_t\fR \fImsg_len\fR, \fBunsigned\fR \fImsg_prio\fR, \fBconst struct timespec *restrict\fR \fIabs_timeout\fR); .fi .LP .nf \fBint\fR \fBmq_reltimedsend_np\fR(\fBmqd_t\fR \fImqdes\fR, \fBconst char *\fR\fImsg_ptr\fR, \fBsize_t\fR \fImsg_len\fR, \fBunsigned\fR \fImsg_prio\fR, \fBconst struct timespec *restrict\fR \fIrel_timeout\fR); .fi .SH DESCRIPTION .LP The \fBmq_send()\fR function adds the message pointed to by the argument \fImsg_ptr\fR to the message queue specified by \fImqdes\fR. The \fImsg_len\fR argument specifies the length of the message in bytes pointed to by \fImsg_ptr\fR. The value of \fImsg_len\fR is less than or equal to the \fImq_msgsize\fR attribute of the message queue, or \fBmq_send()\fR fails. .sp .LP If the specified message queue is not full, \fBmq_send()\fR behaves as if the message is inserted into the message queue at the position indicated by the \fImsg_prio\fR argument. A message with a larger numeric value of \fImsg_prio\fR is inserted before messages with lower values of \fImsg_prio\fR. A message will be inserted after other messages in the queue, if any, with equal \fImsg_prio\fR. The value of \fImsg_prio\fR must range from zero to \fBMQ_PRIO_MAX - 1\fR. .sp .LP If the specified message queue is full and \fBO_NONBLOCK\fR is not set in the message queue description associated with \fImqdes\fR (see \fBmq_open\fR(3C) and \fBmq_setattr\fR(3C)), \fBmq_send()\fR blocks until space becomes available to enqueue the message, or until \fBmq_send()\fR 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 \fBO_NONBLOCK\fR is set in the message queue description associated with \fImqdes\fR, the message is not queued and \fBmq_send()\fR returns an error. .sp .LP The \fBmq_timedsend()\fR function adds a message to the message queue specified by \fImqdes\fR in the manner defined for the \fBmq_send()\fR function. However, if the specified message queue is full and \fBO_NONBLOCK\fR is not set in the message queue description associated with \fImqdes\fR, the wait for sufficient room in the queue is terminated when the specified timeout expires. If \fBO_NONBLOCK\fR is set in the message queue description, this function is equivalent to \fBmq_send()\fR. .sp .LP The \fBmq_reltimedsend_np()\fR function is identical to the \fBmq_timedsend()\fR function, except that the timeout is specified as a relative time interval. .sp .LP For \fBmq_timedsend()\fR, the timeout expires when the absolute time specified by \fIabs_timeout\fR passes, as measured by the \fBCLOCK_REALTIME\fR clock (that is, when the value of that clock equals or exceeds \fIabs_timeout\fR), or if the absolute time specified by \fIabs_timeout\fR has already been passed at the time of the call. .sp .LP For \fBmq_reltimedsend_np()\fR, the timeout expires when the time interval specified by \fIrel_timeout\fR passes, as measured by the \fBCLOCK_REALTIME\fR clock, or if the time interval specified by \fIrel_timeout\fR is negative at the time of the call. .sp .LP The resolution of the timeout is the resolution of the \fBCLOCK_REALTIME\fR clock. The \fBtimespec\fR argument is defined in the <\fBtime.h\fR> header. .sp .LP 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. .SH RETURN VALUES .LP Upon successful completion, \fBmq_send()\fR, \fBmq_timedsend()\fR, and \fBmq_reltimedsend_np()\fR return \fB0\fR. Otherwise, no message is enqueued, the functions return \fB\(mi1\fR, and \fBerrno\fR is set to indicate the error. .SH ERRORS .LP The \fBmq_send()\fR, \fBmq_timedsend()\fR, and \fBmq_reltimedsend_np()\fR functions will fail if: .sp .ne 2 .na \fB\fBEAGAIN\fR \fR .ad .RS 13n The \fBO_NONBLOCK\fR flag is set in the message queue description associated with \fImqdes\fR, and the specified message queue is full. .RE .sp .ne 2 .na \fB\fBEBADF\fR \fR .ad .RS 13n The \fImqdes\fR argument is not a valid message queue descriptor open for writing. .RE .sp .ne 2 .na \fB\fBEINTR\fR \fR .ad .RS 13n A signal interrupted the function call. .RE .sp .ne 2 .na \fB\fBEINVAL\fR\fR .ad .RS 13n The value of \fImsg_prio\fR was outside the valid range. .RE .sp .ne 2 .na \fB\fBEINVAL\fR\fR .ad .RS 13n 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. .RE .sp .ne 2 .na \fB\fBEMSGSIZE\fR \fR .ad .RS 13n The specified message length, \fImsg_len\fR, exceeds the message size attribute of the message queue. .RE .sp .ne 2 .na \fB\fBETIMEDOUT\fR\fR .ad .RS 13n The \fBO_NONBLOCK\fR flag was not set when the message queue was opened, but the timeout expired before the message could be added to the queue. .RE .SH ATTRIBUTES .LP See \fBattributes\fR(7) for descriptions of the following attributes: .sp .sp .TS box; l | l l | l . ATTRIBUTE TYPE ATTRIBUTE VALUE _ Interface Stability Committed _ MT-Level MT-Safe _ Standard See below. .TE .sp .LP For \fBmq_send()\fR and \fBmq_timedsend()\fR, see \fBstandards\fR(7). .SH SEE ALSO .LP .BR mq_open (3C), .BR mq_receive (3C), .BR mq_setattr (3C), .BR sysconf (3C), .BR mqueue.h (3HEAD), .BR attributes (7), .BR standards (7)