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       #define _XOPEN_SOURCE 600
15       #include <time.h>
16       #include <mqueue.h>
17
18       ssize_t mq_timedreceive(mqd_t mqdes, char *msg_ptr,
19                          size_t msg_len, unsigned *msg_prio,
20                          const struct timespec *abs_timeout);
21
22       Link with -lrt.
23

DESCRIPTION

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

RETURN VALUE

55       On  success,  mq_receive()  and  mq_timedreceive() return the number of
56       bytes in the received message; on error, -1 is returned, with errno set
57       to indicate the error.
58

ERRORS

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

CONFORMING TO

79       POSIX.1-2001.
80

NOTES

82       On  Linux,  mq_timedreceive()  is  a system call, and mq_receive() is a
83       library function layered on top of that system call.
84

SEE ALSO

86       mq_close(3),  mq_getattr(3),  mq_notify(3),   mq_open(3),   mq_send(3),
87       mq_unlink(3), feature_test_macros(7), mq_overview(7), time(7)
88

COLOPHON

90       This  page  is  part of release 3.25 of the Linux man-pages project.  A
91       description of the project, and information about reporting  bugs,  can
92       be found at http://www.kernel.org/doc/man-pages/.
93
94
95
96Linux                             2010-02-25                     MQ_RECEIVE(3)
Impressum