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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

CONFORMING TO

77       POSIX.1-2001.
78

SEE ALSO

80       mq_close(3),   mq_getattr(3),   mq_notify(3),  mq_open(3),  mq_send(3),
81       mq_unlink(3), feature_test_macros(7), mq_overview(7)
82
83
84
85Linux 2.6.16                      2006-02-25                     MQ_RECEIVE(3)
Impressum