]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/mq_receive.3
getcpu.2, sendfile.2, cmsg.3, rtnetlink.3, arp.7, ddp.7, fifo.7, icmp.7, ip.7, ipv6...
[thirdparty/man-pages.git] / man3 / mq_receive.3
CommitLineData
80a99f39 1'\" t
c11b1abf 2.\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
80a99f39 3.\"
4b72fb64 4.\" %%%LICENSE_START(verbatim)
80a99f39
MK
5.\" Permission is granted to make and distribute verbatim copies of this
6.\" manual provided the copyright notice and this permission notice are
7.\" preserved on all copies.
8.\"
9.\" Permission is granted to copy and distribute modified versions of this
10.\" manual under the conditions for verbatim copying, provided that the
11.\" entire resulting derived work is distributed under the terms of a
12.\" permission notice identical to this one.
c13182ef 13.\"
80a99f39
MK
14.\" Since the Linux kernel and libraries are constantly changing, this
15.\" manual page may be incorrect or out-of-date. The author(s) assume no
16.\" responsibility for errors or omissions, or for damages resulting from
10d76543
MK
17.\" the use of the information contained herein. The author(s) may not
18.\" have taken the same level of care in the production of this manual,
19.\" which is licensed free of charge, as they might when working
20.\" professionally.
c13182ef 21.\"
80a99f39
MK
22.\" Formatted or processed versions of this manual, if unaccompanied by
23.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 24.\" %%%LICENSE_END
80a99f39 25.\"
50831f9b 26.TH MQ_RECEIVE 3 2010-09-20 "Linux" "Linux Programmer's Manual"
80a99f39
MK
27.SH NAME
28mq_receive, mq_timedreceive \- receive a message from a message queue
29.SH SYNOPSIS
30.nf
31.B #include <mqueue.h>
32.sp
36e212c6
MK
33.BI "ssize_t mq_receive(mqd_t " mqdes ", char *" msg_ptr ,
34.BI " size_t " msg_len ", unsigned *" msg_prio );
80a99f39 35.sp
80a99f39
MK
36.B #include <time.h>
37.B #include <mqueue.h>
38.sp
36e212c6
MK
39.BI "ssize_t mq_timedreceive(mqd_t " mqdes ", char *" msg_ptr ,
40.BI " size_t " msg_len ", unsigned *" msg_prio ,
41.BI " const struct timespec *" abs_timeout );
80a99f39 42.fi
1b2d3fca
MK
43.sp
44Link with \fI\-lrt\fP.
9a30939e
MK
45.sp
46.ad l
47.in -4n
48Feature Test Macro Requirements for glibc (see
49.BR feature_test_macros (7)):
50.in
51.sp
52.BR mq_timedreceive ():
53.RS 4
54_XOPEN_SOURCE\ >=\ 600 || _POSIX_C_SOURCE\ >=\ 200112L
55.RE
56.ad
80a99f39
MK
57.SH DESCRIPTION
58.BR mq_receive ()
c13182ef
MK
59removes the oldest message with the highest priority from
60the message queue referred to by the descriptor
80a99f39
MK
61.IR mqdes ,
62and places it in the buffer pointed to by
63.IR msg_ptr .
64The
65.I msg_len
66argument specifies the size of the buffer pointed to by
67.IR msg_ptr ;
68this must be greater than the
69.I mq_msgsize
c13182ef 70attribute of the queue (see
80a99f39
MK
71.BR mq_getattr (3)).
72If
37f02e32 73.I msg_prio
c13182ef 74is not NULL, then the buffer to which it points is used
80a99f39
MK
75to return the priority associated with the received message.
76
77If the queue is empty, then, by default,
78.BR mq_receive ()
79blocks until a message becomes available,
80or the call is interrupted by a signal handler.
c13182ef 81If the
80a99f39
MK
82.B O_NONBLOCK
83flag is enabled for the message queue description,
84then the call instead fails immediately with the error
85.BR EAGAIN .
86
87.BR mq_timedreceive ()
88behaves just like
89.BR mq_receive (),
90except that if the queue is empty and the
91.B O_NONBLOCK
92flag is not enabled for the message queue description, then
93.I abs_timeout
c13182ef 94points to a structure which specifies a ceiling on the time for which
80a99f39
MK
95the call will block.
96This ceiling is an absolute timeout in seconds and nanoseconds
f49c451a 97since the Epoch, 1970-01-01 00:00:00 +0000 (UTC), and it is
80a99f39
MK
98specified in the following structure:
99.sp
bd191423 100.in +4n
80a99f39
MK
101.nf
102struct timespec {
103 time_t tv_sec; /* seconds */
104 long tv_nsec; /* nanoseconds */
105};
106
107.fi
bd191423 108.in
80a99f39
MK
109If no message is available,
110and the timeout has already expired by the time of the call,
111.BR mq_timedreceive ()
112returns immediately.
113.SH RETURN VALUE
114On success,
115.BR mq_receive ()
116and
117.BR mq_timedreceive ()
118return the number of bytes in the received message;
119on error, \-1 is returned, with
c13182ef 120.I errno
80a99f39
MK
121set to indicate the error.
122.SH ERRORS
123.TP
124.B EAGAIN
125The queue was empty, and the
126.B O_NONBLOCK
127flag was set for the message queue description referred to by
128.IR mqdes .
129.TP
130.B EBADF
c13182ef 131The descriptor specified in
80a99f39
MK
132.I mqdes
133was invalid.
134.TP
80a99f39 135.B EINTR
01538d0d
MK
136The call was interrupted by a signal handler; see
137.BR signal (7).
80a99f39
MK
138.TP
139.B EINVAL
c13182ef 140The call would have blocked, and
80a99f39
MK
141.I abs_timeout
142was invalid, either because
143.I tv_sec
144was less than zero, or because
c13182ef 145.I tv_nsec
80a99f39
MK
146was less than zero or greater than 1000 million.
147.TP
eab64696 148.B EMSGSIZE
0daa9e92 149.I msg_len
eab64696
MK
150was less than the
151.I mq_msgsize
152attribute of the message queue.
153.TP
80a99f39
MK
154.B ETIMEDOUT
155The call timed out before a message could be transferred.
156.SH CONFORMING TO
157POSIX.1-2001.
c89e428b
MK
158.SH NOTES
159On Linux,
160.BR mq_timedreceive ()
161is a system call, and
162.BR mq_receive ()
163is a library function layered on top of that system call.
47297adb 164.SH SEE ALSO
80a99f39
MK
165.BR mq_close (3),
166.BR mq_getattr (3),
167.BR mq_notify (3),
168.BR mq_open (3),
169.BR mq_send (3),
170.BR mq_unlink (3),
1d7c4d16
MK
171.BR mq_overview (7),
172.BR time (7)