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 *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 *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           _XOPEN_SOURCE >= 600 || _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 descriptor mqdes, and places it in
31       the  buffer  pointed to by msg_ptr.  The msg_len argument specifies the
32       size of the buffer pointed to by msg_ptr; this must be greater than the
33       mq_msgsize  attribute of the queue (see mq_getattr(3)).  If msg_prio is
34       not NULL, then the buffer to which it points is used to return the pri‐
35       ority associated with the received message.
36
37       If  the  queue  is empty, then, by default, mq_receive() blocks until a
38       message becomes available, or the call is interrupted by a signal  han‐
39       dler.  If the O_NONBLOCK flag is enabled for the message queue descrip‐
40       tion, then the call instead fails immediately with the error EAGAIN.
41
42       mq_timedreceive() behaves just like mq_receive(), except  that  if  the
43       queue  is  empty and the O_NONBLOCK flag is not enabled for the message
44       queue description, then abs_timeout points to a structure which  speci‐
45       fies a ceiling on the time for which the call will block.  This ceiling
46       is an absolute timeout in seconds  and  nanoseconds  since  the  Epoch,
47       1970-01-01  00:00:00  +0000 (UTC), and it is specified in the following
48       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.
68
69       EINTR  The call was interrupted by a signal handler; see signal(7).
70
71       EINVAL The call would have blocked, and abs_timeout was invalid, either
72              because  tv_sec  was less than zero, or because tv_nsec was less
73              than zero or greater than 1000 million.
74
75       EMSGSIZE
76              msg_len was less than the mq_msgsize attribute  of  the  message
77              queue.
78
79       ETIMEDOUT
80              The call timed out before a message could be transferred.
81

CONFORMING TO

83       POSIX.1-2001.
84

NOTES

86       On  Linux,  mq_timedreceive()  is  a system call, and mq_receive() is a
87       library function layered on top of that system call.
88

SEE ALSO

90       mq_close(3),  mq_getattr(3),  mq_notify(3),   mq_open(3),   mq_send(3),
91       mq_unlink(3), mq_overview(7), time(7)
92

COLOPHON

94       This  page  is  part of release 3.53 of the Linux man-pages project.  A
95       description of the project, and information about reporting  bugs,  can
96       be found at http://www.kernel.org/doc/man-pages/.
97
98
99
100Linux                             2010-09-20                     MQ_RECEIVE(3)
Impressum