1 '\" te
   2 .\" Copyright (c) 2008, Sun Microsystems, Inc.  All Rights Reserved.
   3 .\" Copyright 1989 AT&T
   4 .\" Portions Copyright (c) 1992, X/Open Company Limited.  All Rights Reserved.
   5 .\" 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
   6 .\" http://www.opengroup.org/bookstore/.
   7 .\" 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.
   8 .\"  This notice shall appear on any product containing this material.
   9 .\" 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.
  10 .\" 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.
  11 .\" 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]
  12 .TH MQ_SEND 3C "Feb 5, 2008"
  13 .SH NAME
  14 mq_send, mq_timedsend, mq_reltimedsend_np \- send a message to a message queue
  15 .SH SYNOPSIS
  16 .LP
  17 .nf
  18 #include <mqueue.h>
  19 
  20 \fBint\fR \fBmq_send\fR(\fBmqd_t\fR \fImqdes\fR, \fBconst char *\fR\fImsg_ptr\fR, \fBsize_t\fR \fImsg_len\fR,
  21      \fBunsigned\fR \fImsg_prio\fR);
  22 .fi
  23 
  24 .LP
  25 .nf
  26 #include <mqueue.h>
  27 #include <time.h>
  28 
  29 \fBint\fR \fBmq_timedsend\fR(\fBmqd_t\fR \fImqdes\fR, \fBconst char *\fR\fImsg_ptr\fR,
  30      \fBsize_t\fR \fImsg_len\fR, \fBunsigned\fR \fImsg_prio\fR,
  31      \fBconst struct timespec *restrict\fR \fIabs_timeout\fR);
  32 .fi
  33 
  34 .LP
  35 .nf
  36 \fBint\fR \fBmq_reltimedsend_np\fR(\fBmqd_t\fR \fImqdes\fR, \fBconst char *\fR\fImsg_ptr\fR,
  37      \fBsize_t\fR \fImsg_len\fR, \fBunsigned\fR \fImsg_prio\fR,
  38      \fBconst struct timespec *restrict\fR \fIrel_timeout\fR);
  39 .fi
  40 
  41 .SH DESCRIPTION
  42 .sp
  43 .LP
  44 The \fBmq_send()\fR function adds the message pointed to by the argument
  45 \fImsg_ptr\fR to the message queue specified by \fImqdes\fR. The \fImsg_len\fR
  46 argument specifies the length of the message in bytes pointed to by
  47 \fImsg_ptr\fR. The value of \fImsg_len\fR is less than or equal to the
  48 \fImq_msgsize\fR attribute of the message queue, or \fBmq_send()\fR fails.
  49 .sp
  50 .LP
  51 If the specified message queue is not full, \fBmq_send()\fR behaves as if the
  52 message is inserted into the message queue at the position indicated by the
  53 \fImsg_prio\fR argument. A message with a larger numeric value of
  54 \fImsg_prio\fR is inserted before messages with lower values of \fImsg_prio\fR.
  55 A message will be inserted after other messages in the queue, if any, with
  56 equal \fImsg_prio\fR. The value of \fImsg_prio\fR must be greater than zero and
  57 less than or equal to  \fBMQ_PRIO_MAX\fR.
  58 .sp
  59 .LP
  60 If the specified message queue is full and \fBO_NONBLOCK\fR is not set in the
  61 message queue description associated with \fImqdes\fR (see \fBmq_open\fR(3C)
  62 and \fBmq_setattr\fR(3C)), \fBmq_send()\fR blocks until space becomes available
  63 to enqueue the message, or until \fBmq_send()\fR is interrupted by a signal. If
  64 more than one thread is waiting to send when space becomes available in the
  65 message queue, then the thread of the highest priority which has been waiting
  66 the longest is unblocked to send its message. Otherwise, it is unspecified
  67 which waiting thread is unblocked. If the specified message queue is full and
  68 \fBO_NONBLOCK\fR is set in the message queue description associated with
  69 \fImqdes\fR, the message is not queued and \fBmq_send()\fR returns an error.
  70 .sp
  71 .LP
  72 The \fBmq_timedsend()\fR function adds a message to the message queue specified
  73 by \fImqdes\fR in the manner defined for the \fBmq_send()\fR function. However,
  74 if the specified message queue is full and \fBO_NONBLOCK\fR is not set in the
  75 message queue description associated with \fImqdes\fR, the wait for sufficient
  76 room in the queue is terminated when the specified timeout expires. If
  77 \fBO_NONBLOCK\fR is set in the message queue description, this function is
  78 equivalent to \fBmq_send()\fR.
  79 .sp
  80 .LP
  81 The \fBmq_reltimedsend_np()\fR function is identical to the
  82 \fBmq_timedsend()\fR function, except that the timeout is specified as a
  83 relative time interval.
  84 .sp
  85 .LP
  86 For \fBmq_timedsend()\fR, the timeout expires when the absolute time specified
  87 by \fIabs_timeout\fR passes, as measured by the \fBCLOCK_REALTIME\fR clock
  88 (that is, when the value of that clock equals or exceeds \fIabs_timeout\fR), or
  89 if the absolute time specified by \fIabs_timeout\fR has already been passed at
  90 the time of the call.
  91 .sp
  92 .LP
  93 For \fBmq_reltimedsend_np()\fR, the timeout expires when the time interval
  94 specified by \fIrel_timeout\fR passes, as measured by the \fBCLOCK_REALTIME\fR
  95 clock, or if the time interval specified by \fIrel_timeout\fR is negative at
  96 the time of the call.
  97 .sp
  98 .LP
  99 The resolution of the timeout is the resolution of the \fBCLOCK_REALTIME\fR
 100 clock. The \fBtimespec\fR argument is defined in the <\fBtime.h\fR> header.
 101 .sp
 102 .LP
 103 Under no circumstance does the operation fail with a timeout if there is
 104 sufficient room in the queue to add the message immediately. The validity of
 105 the timeout parameter need not be checked when there is sufficient room in the
 106 queue.
 107 .SH RETURN VALUES
 108 .sp
 109 .LP
 110 Upon successful completion, \fBmq_send()\fR, \fBmq_timedsend()\fR, and
 111 \fBmq_reltimedsend_np()\fR return \fB0\fR. Otherwise, no message is enqueued,
 112 the functions return \fB\(mi1\fR, and \fBerrno\fR is set to indicate the error.
 113 .SH ERRORS
 114 .sp
 115 .LP
 116 The \fBmq_send()\fR, \fBmq_timedsend()\fR, and \fBmq_reltimedsend_np()\fR
 117 functions will fail if:
 118 .sp
 119 .ne 2
 120 .na
 121 \fB\fBEAGAIN\fR \fR
 122 .ad
 123 .RS 13n
 124 The  \fBO_NONBLOCK\fR flag is set in the message queue description associated
 125 with \fImqdes\fR, and the specified message queue is full.
 126 .RE
 127 
 128 .sp
 129 .ne 2
 130 .na
 131 \fB\fBEBADF\fR \fR
 132 .ad
 133 .RS 13n
 134 The \fImqdes\fR argument is not a valid message queue descriptor open for
 135 writing.
 136 .RE
 137 
 138 .sp
 139 .ne 2
 140 .na
 141 \fB\fBEINTR\fR \fR
 142 .ad
 143 .RS 13n
 144 A signal interrupted the function call.
 145 .RE
 146 
 147 .sp
 148 .ne 2
 149 .na
 150 \fB\fBEINVAL\fR\fR
 151 .ad
 152 .RS 13n
 153 The value of \fImsg_prio\fR was outside the valid range.
 154 .RE
 155 
 156 .sp
 157 .ne 2
 158 .na
 159 \fB\fBEINVAL\fR\fR
 160 .ad
 161 .RS 13n
 162 The process or thread would have blocked, and the timeout parameter specified a
 163 nanoseconds field value less than zero or greater than or equal to 1,000
 164 million.
 165 .RE
 166 
 167 .sp
 168 .ne 2
 169 .na
 170 \fB\fBEMSGSIZE\fR \fR
 171 .ad
 172 .RS 13n
 173 The specified message length, \fImsg_len\fR, exceeds the message size attribute
 174 of the message queue.
 175 .RE
 176 
 177 .sp
 178 .ne 2
 179 .na
 180 \fB\fBETIMEDOUT\fR\fR
 181 .ad
 182 .RS 13n
 183 The \fBO_NONBLOCK\fR flag was not set when the message queue was opened, but
 184 the timeout expired before the message could be added to the queue.
 185 .RE
 186 
 187 .SH ATTRIBUTES
 188 .sp
 189 .LP
 190 See \fBattributes\fR(5) for descriptions of the following attributes:
 191 .sp
 192 
 193 .sp
 194 .TS
 195 box;
 196 l | l
 197 l | l .
 198 ATTRIBUTE TYPE  ATTRIBUTE VALUE
 199 _
 200 Interface Stability     Committed
 201 _
 202 MT-Level        MT-Safe
 203 _
 204 Standard        See below.
 205 .TE
 206 
 207 .sp
 208 .LP
 209 For \fBmq_send()\fR and \fBmq_timedsend()\fR, see \fBstandards\fR(5).
 210 .SH SEE ALSO
 211 .sp
 212 .LP
 213 \fBsysconf\fR(3C), \fBmqueue.h\fR(3HEAD), \fBmq_open\fR(3C),
 214 \fBmq_receive\fR(3C), \fBmq_setattr\fR(3C), \fBattributes\fR(5),
 215 \fBstandards\fR(5)