1MQ_RECEIVE(3)              Linux Programmer's Manual             MQ_RECEIVE(3)
2
3
4

NAME

6       mq_receive, mq_timedreceive - receive a message from a message queue
7

SYNOPSIS

9       #include <mqueue.h>
10
11       ssize_t mq_receive(mqd_t mqdes, char *msg_ptr,
12                          size_t msg_len, unsigned int *msg_prio);
13
14       #include <time.h>
15       #include <mqueue.h>
16
17       ssize_t mq_timedreceive(mqd_t mqdes, char *msg_ptr,
18                          size_t msg_len, unsigned int *msg_prio,
19                          const struct timespec *abs_timeout);
20
21       Link with -lrt.
22
23   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
24
25       mq_timedreceive():
26           _POSIX_C_SOURCE >= 200112L
27

DESCRIPTION

29       mq_receive()  removes the oldest message with the highest priority from
30       the message queue referred to by the message  queue  descriptor  mqdes,
31       and  places  it in the buffer pointed to by msg_ptr.  The msg_len argu‐
32       ment specifies the size of the buffer pointed to by msg_ptr; this  must
33       be  greater than or equal to the mq_msgsize attribute of the queue (see
34       mq_getattr(3)).  If msg_prio is not NULL, then the buffer to  which  it
35       points is used to return the priority associated with the received mes‐
36       sage.
37
38       If the queue is empty, then, by default, mq_receive()  blocks  until  a
39       message  becomes available, or the call is interrupted by a signal han‐
40       dler.  If the O_NONBLOCK flag is enabled for the message queue descrip‐
41       tion, then the call instead fails immediately with the error EAGAIN.
42
43       mq_timedreceive()  behaves  just  like mq_receive(), except that if the
44       queue is empty and the O_NONBLOCK flag is not enabled for  the  message
45       queue  description, then abs_timeout points to a structure which speci‐
46       fies how long the call will block.  This value is an  absolute  timeout
47       in  seconds  and nanoseconds since the Epoch, 1970-01-01 00:00:00 +0000
48       (UTC), specified in the following structure:
49
50           struct timespec {
51               time_t tv_sec;        /* seconds */
52               long   tv_nsec;       /* nanoseconds */
53           };
54
55       If no message is available, and the timeout has already expired by  the
56       time of the call, mq_timedreceive() returns immediately.
57

RETURN VALUE

59       On  success,  mq_receive()  and  mq_timedreceive() return the number of
60       bytes in the received message; on error, -1 is returned, with errno set
61       to indicate the error.
62

ERRORS

64       EAGAIN The  queue  was  empty,  and the O_NONBLOCK flag was set for the
65              message queue description referred to by mqdes.
66
67       EBADF  The descriptor specified in mqdes was invalid or not opened  for
68              reading.
69
70       EINTR  The call was interrupted by a signal handler; see signal(7).
71
72       EINVAL The call would have blocked, and abs_timeout was invalid, either
73              because tv_sec was less than zero, or because tv_nsec  was  less
74              than zero or greater than 1000 million.
75
76       EMSGSIZE
77              msg_len  was  less  than the mq_msgsize attribute of the message
78              queue.
79
80       ETIMEDOUT
81              The call timed out before a message could be transferred.
82

ATTRIBUTES

84       For  an  explanation  of  the  terms  used   in   this   section,   see
85       attributes(7).
86
87       ┌────────────────────────────────┬───────────────┬─────────┐
88Interface                       Attribute     Value   
89       ├────────────────────────────────┼───────────────┼─────────┤
90mq_receive(), mq_timedreceive() │ Thread safety │ MT-Safe │
91       └────────────────────────────────┴───────────────┴─────────┘

CONFORMING TO

93       POSIX.1-2001, POSIX.1-2008.
94

NOTES

96       On  Linux,  mq_timedreceive()  is  a system call, and mq_receive() is a
97       library function layered on top of that system call.
98

SEE ALSO

100       mq_close(3),  mq_getattr(3),  mq_notify(3),   mq_open(3),   mq_send(3),
101       mq_unlink(3), mq_overview(7), time(7)
102

COLOPHON

104       This  page  is  part of release 5.02 of the Linux man-pages project.  A
105       description of the project, information about reporting bugs,  and  the
106       latest     version     of     this    page,    can    be    found    at
107       https://www.kernel.org/doc/man-pages/.
108
109
110
111Linux                             2017-09-15                     MQ_RECEIVE(3)
Impressum