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