man-pages/man3/mq_send.3.html
2021-03-31 01:06:50 +01:00

288 lines
6.7 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of MQ_SEND</TITLE>
</HEAD><BODY>
<H1>MQ_SEND</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
mq_send, mq_timedsend - send a message to a message queue
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#include &lt;<A HREF="file:///usr/include/mqueue.h">mqueue.h</A>&gt;</B>
<B>int mq_send(mqd_t </B><I>mqdes</I><B>, const char *</B><I>msg_ptr</I><B>,</B>
<B> size_t </B><I>msg_len</I><B>, unsigned int </B><I>msg_prio</I><B>);</B>
<B>#include &lt;<A HREF="file:///usr/include/time.h">time.h</A>&gt;</B>
<B>#include &lt;<A HREF="file:///usr/include/mqueue.h">mqueue.h</A>&gt;</B>
<B>int mq_timedsend(mqd_t </B><I>mqdes</I><B>, const char *</B><I>msg_ptr</I><B>,</B>
<B> size_t </B><I>msg_len</I><B>, unsigned int </B><I>msg_prio</I><B>,</B>
<B> const struct timespec *</B><I>abs_timeout</I><B>);</B>
</PRE>
<P>
Link with <I>-lrt</I>.
<P>
Feature Test Macro Requirements for glibc (see
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
<P>
<B>mq_timedsend</B>():
<DL COMPACT><DT id="1"><DD>
_POSIX_C_SOURCE&nbsp;&gt;=&nbsp;200112L
</DL>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
<B>mq_send</B>()
adds the message pointed to by
<I>msg_ptr</I>
to the message queue referred to by the message queue descriptor
<I>mqdes</I>.
The
<I>msg_len</I>
argument specifies the length of the message pointed to by
<I>msg_ptr</I>;
this length must be less than or equal to the queue's
<I>mq_msgsize</I>
attribute.
Zero-length messages are allowed.
<P>
The
<I>msg_prio</I>
argument is a nonnegative integer that specifies the priority
of this message.
Messages are placed on the queue in decreasing order of priority,
with newer messages of the same priority being placed after
older messages with the same priority.
See
<B><A HREF="/cgi-bin/man/man2html?7+mq_overview">mq_overview</A></B>(7)
for details on the range for the message priority.
<P>
If the message queue is already full
(i.e., the number of messages on the queue equals the queue's
<I>mq_maxmsg</I>
attribute), then, by default,
<B>mq_send</B>()
blocks until sufficient space becomes available to allow the message
to be queued, or until the call is interrupted by a signal handler.
If the
<B>O_NONBLOCK</B>
flag is enabled for the message queue description,
then the call instead fails immediately with the error
<B>EAGAIN</B>.
<P>
<B>mq_timedsend</B>()
behaves just like
<B>mq_send</B>(),
except that if the queue is full and the
<B>O_NONBLOCK</B>
flag is not enabled for the message queue description, then
<I>abs_timeout</I>
points to a structure which specifies how long the call will block.
This value is an absolute timeout in seconds and nanoseconds
since the Epoch, 1970-01-01 00:00:00 +0000 (UTC),
specified in the following structure:
<P>
struct timespec {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;time_t&nbsp;tv_sec;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;seconds&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;long&nbsp;&nbsp;&nbsp;tv_nsec;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;nanoseconds&nbsp;*/
};
<P>
If the message queue is full,
and the timeout has already expired by the time of the call,
<B>mq_timedsend</B>()
returns immediately.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
On success,
<B>mq_send</B>()
and
<B>mq_timedsend</B>()
return zero; on error, -1 is returned, with
<I>errno</I>
set to indicate the error.
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
<DL COMPACT>
<DT id="2"><B>EAGAIN</B>
<DD>
The queue was full, and the
<B>O_NONBLOCK</B>
flag was set for the message queue description referred to by
<I>mqdes</I>.
<DT id="3"><B>EBADF</B>
<DD>
The descriptor specified in
<I>mqdes</I>
was invalid or not opened for writing.
<DT id="4"><B>EINTR</B>
<DD>
The call was interrupted by a signal handler; see
<B><A HREF="/cgi-bin/man/man2html?7+signal">signal</A></B>(7).
<DT id="5"><B>EINVAL</B>
<DD>
The call would have blocked, and
<I>abs_timeout</I>
was invalid, either because
<I>tv_sec</I>
was less than zero, or because
<I>tv_nsec</I>
was less than zero or greater than 1000 million.
<DT id="6"><B>EMSGSIZE</B>
<DD>
<I>msg_len</I>
was greater than the
<I>mq_msgsize</I>
attribute of the message queue.
<DT id="7"><B>ETIMEDOUT</B>
<DD>
The call timed out before a message could be transferred.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>ATTRIBUTES</H2>
For an explanation of the terms used in this section, see
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
<TABLE BORDER>
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
<TR VALIGN=top><TD>
<B>mq_send</B>(),
<B>mq_timedsend</B>()
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
</TABLE>
<A NAME="lbAH">&nbsp;</A>
<H2>CONFORMING TO</H2>
POSIX.1-2001, POSIX.1-2008.
<A NAME="lbAI">&nbsp;</A>
<H2>NOTES</H2>
On Linux,
<B>mq_timedsend</B>()
is a system call, and
<B>mq_send</B>()
is a library function layered on top of that system call.
<A NAME="lbAJ">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?3+mq_close">mq_close</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+mq_getattr">mq_getattr</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+mq_notify">mq_notify</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+mq_open">mq_open</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+mq_receive">mq_receive</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+mq_unlink">mq_unlink</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?7+mq_overview">mq_overview</A></B>(7),
<B><A HREF="/cgi-bin/man/man2html?7+time">time</A></B>(7)
<A NAME="lbAK">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="8"><A HREF="#lbAB">NAME</A><DD>
<DT id="9"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="10"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="11"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="12"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="13"><A HREF="#lbAG">ATTRIBUTES</A><DD>
<DT id="14"><A HREF="#lbAH">CONFORMING TO</A><DD>
<DT id="15"><A HREF="#lbAI">NOTES</A><DD>
<DT id="16"><A HREF="#lbAJ">SEE ALSO</A><DD>
<DT id="17"><A HREF="#lbAK">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:48 GMT, March 31, 2021
</BODY>
</HTML>