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

NAME

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

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

EXAMPLES

119       None.
120

APPLICATION USAGE

122       None.
123

RATIONALE

125       None.
126

FUTURE DIRECTIONS

128       None.
129

SEE ALSO

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