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

278 lines
6.5 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of MQ_RECEIVE</TITLE>
</HEAD><BODY>
<H1>MQ_RECEIVE</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_receive, mq_timedreceive - receive a message from 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>ssize_t mq_receive(mqd_t </B><I>mqdes</I><B>, 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>ssize_t mq_timedreceive(mqd_t </B><I>mqdes</I><B>, 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_timedreceive</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_receive</B>()
removes the oldest message with the highest priority from
the message queue referred to by the message queue descriptor
<I>mqdes</I>,
and places it in the buffer pointed to by
<I>msg_ptr</I>.
The
<I>msg_len</I>
argument specifies the size of the buffer pointed to by
<I>msg_ptr</I>;
this must be greater than or equal to the
<I>mq_msgsize</I>
attribute of the queue (see
<B><A HREF="/cgi-bin/man/man2html?3+mq_getattr">mq_getattr</A></B>(3)).
If
<I>msg_prio</I>
is not NULL, then the buffer to which it points is used
to return the priority associated with the received message.
<P>
If the queue is empty, then, by default,
<B>mq_receive</B>()
blocks until a message becomes available,
or 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_timedreceive</B>()
behaves just like
<B>mq_receive</B>(),
except that if the queue is empty 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 no message is available,
and the timeout has already expired by the time of the call,
<B>mq_timedreceive</B>()
returns immediately.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
On success,
<B>mq_receive</B>()
and
<B>mq_timedreceive</B>()
return the number of bytes in the received message;
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 empty, 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 reading.
<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 less 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_receive</B>(),
<B>mq_timedreceive</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_timedreceive</B>()
is a system call, and
<B>mq_receive</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_send">mq_send</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>