1MQ_RECEIVE(3P)             POSIX Programmer's Manual            MQ_RECEIVE(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       mq_receive, mq_timedreceive — receive a message from  a  message  queue
14       (REALTIME)
15

SYNOPSIS

17       #include <mqueue.h>
18
19       ssize_t mq_receive(mqd_t mqdes, char *msg_ptr, size_t msg_len,
20           unsigned *msg_prio);
21
22       #include <mqueue.h>
23       #include <time.h>
24
25       ssize_t mq_timedreceive(mqd_t mqdes, char *restrict msg_ptr,
26           size_t msg_len, unsigned *restrict msg_prio,
27           const struct timespec *restrict abstime);
28

DESCRIPTION

30       The  mq_receive() function shall receive the oldest of the highest pri‐
31       ority message(s) from the message queue specified  by  mqdes.   If  the
32       size of the buffer in bytes, specified by the msg_len argument, is less
33       than the mq_msgsize attribute of the message queue, the function  shall
34       fail  and  return  an  error.  Otherwise, the selected message shall be
35       removed from the queue and copied to  the  buffer  pointed  to  by  the
36       msg_ptr argument.
37
38       If  the  value  of  msg_len  is greater than {SSIZE_MAX}, the result is
39       implementation-defined.
40
41       If the argument msg_prio is not NULL, the priority of the selected mes‐
42       sage shall be stored in the location referenced by msg_prio.
43
44       If  the  specified  message queue is empty and O_NONBLOCK is not set in
45       the message queue description associated with mqdes, mq_receive() shall
46       block  until  a  message  is  enqueued  on  the  message queue or until
47       mq_receive() is interrupted by a signal. If more  than  one  thread  is
48       waiting  to  receive a message when a message arrives at an empty queue
49       and the Priority Scheduling option is supported,  then  the  thread  of
50       highest priority that has been waiting the longest shall be selected to
51       receive the message. Otherwise, it is unspecified which waiting  thread
52       receives  the  message.  If  the  specified  message queue is empty and
53       O_NONBLOCK is set in the  message  queue  description  associated  with
54       mqdes,  no  message  shall  be removed from the queue, and mq_receive()
55       shall return an error.
56
57       The mq_timedreceive() function shall receive the oldest of the  highest
58       priority  messages  from  the  message  queue  specified  by  mqdes  as
59       described for the mq_receive() function. However, if O_NONBLOCK was not
60       specified when the message queue was opened via the mq_open() function,
61       and no message exists on the queue to satisfy the receive, the wait for
62       such  a message shall be terminated when the specified timeout expires.
63       If O_NONBLOCK is set, this function is equivalent to mq_receive().
64
65       The timeout expires when the absolute time specified by abstime passes,
66       as measured by the clock on which timeouts are based (that is, when the
67       value of that clock equals or exceeds abstime), or if the absolute time
68       specified by abstime has already been passed at the time of the call.
69
70       The timeout shall be based on the CLOCK_REALTIME clock.  The resolution
71       of the timeout shall be the resolution of the  clock  on  which  it  is
72       based. The timespec argument is defined in the <time.h> header.
73
74       Under no circumstance shall the operation fail with a timeout if a mes‐
75       sage can be removed from the message queue immediately. The validity of
76       the  abstime  parameter need not be checked if a message can be removed
77       from the message queue immediately.
78

RETURN VALUE

80       Upon successful  completion,  the  mq_receive()  and  mq_timedreceive()
81       functions  shall return the length of the selected message in bytes and
82       the message shall be removed from  the  queue.  Otherwise,  no  message
83       shall  be removed from the queue, the functions shall return a value of
84       −1, and set errno to indicate the error.
85

ERRORS

87       These functions shall fail if:
88
89       EAGAIN O_NONBLOCK was set in the message  description  associated  with
90              mqdes, and the specified message queue is empty.
91
92       EBADF  The  mqdes argument is not a valid message queue descriptor open
93              for reading.
94
95       EMSGSIZE
96              The specified message buffer size, msg_len,  is  less  than  the
97              message size attribute of the message queue.
98
99       EINTR  The  mq_receive() or mq_timedreceive() operation was interrupted
100              by a signal.
101
102       EINVAL The process or thread would have blocked, and the abstime param‐
103              eter  specified  a  nanoseconds  field  value  less than zero or
104              greater than or equal to 1000 million.
105
106       ETIMEDOUT
107              The O_NONBLOCK flag was not  set  when  the  message  queue  was
108              opened, but no message arrived on the queue before the specified
109              timeout expired.
110
111       These functions may fail if:
112
113       EBADMSG
114              The implementation has detected a data corruption  problem  with
115              the message.
116
117       The following sections are informative.
118

EXAMPLES

120       None.
121

APPLICATION USAGE

123       None.
124

RATIONALE

126       None.
127

FUTURE DIRECTIONS

129       None.
130

SEE ALSO

132       mq_open(), mq_send(), msgctl(), msgget(), msgrcv(), msgsnd(), time()
133
134       The Base Definitions volume of POSIX.1‐2008, <mqueue.h>, <time.h>
135
137       Portions  of  this text are reprinted and reproduced in electronic form
138       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
139       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
140       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
141       cal  and  Electronics  Engineers,  Inc  and  The  Open Group.  (This is
142       POSIX.1-2008 with the 2013 Technical Corrigendum  1  applied.)  In  the
143       event of any discrepancy between this version and the original IEEE and
144       The Open Group Standard, the original IEEE and The Open Group  Standard
145       is  the  referee document. The original Standard can be obtained online
146       at http://www.unix.org/online.html .
147
148       Any typographical or formatting errors that appear  in  this  page  are
149       most likely to have been introduced during the conversion of the source
150       files to man page format. To report such errors,  see  https://www.ker
151       nel.org/doc/man-pages/reporting_bugs.html .
152
153
154
155IEEE/The Open Group                  2013                       MQ_RECEIVE(3P)
Impressum