source: rtems-docs/posix_users/message_passing.rst @ 489740f

4.115
Last change on this file since 489740f was 489740f, checked in by Chris Johns <chrisj@…>, on 05/20/16 at 02:47:09

Set SPDX License Identifier in each source file.

  • Property mode set to 100644
File size: 28.4 KB
Line 
1.. comment SPDX-License-Identifier: CC-BY-SA-4.0
2
3.. COMMENT: COPYRIGHT (c) 1988-2014.
4.. COMMENT: On-Line Applications Research Corporation (OAR).
5.. COMMENT: All rights reserved.
6
7Message Passing Manager
8#######################
9
10Introduction
11============
12
13The message passing manager is the means to provide communication and
14synchronization capabilities using POSIX message queues.
15
16The directives provided by the message passing manager are:
17
18- mq_open_ - Open a Message Queue
19
20- mq_close_ - Close a Message Queue
21
22- mq_unlink_ - Remove a Message Queue
23
24- mq_send_ - Send a Message to a Message Queue
25
26- mq_receive_ - Receive a Message from a Message Queue
27
28- mq_notify_ - Notify Process that a Message is Available
29
30- mq_setattr_ - Set Message Queue Attributes
31
32- mq_getattr_ - Get Message Queue Attributes
33
34Background
35==========
36
37Theory
38------
39
40Message queues are named objects that operate with readers and writers.  In
41addition, a message queue is a priority queue of discrete messages.  POSIX
42message queues offer a certain, basic amount of application access to, and
43control over, the message queue geometry that can be changed.
44
45Messages
46--------
47
48A message is a variable length buffer where information can be stored to
49support communication. The length of the message and the information stored in
50that message are user-defined and can be actual data, pointer(s), or
51empty. There is a maximum acceptable length for a message that is associated
52with each message queue.
53
54Message Queues
55--------------
56
57Message queues are named objects similar to the pipes of POSIX. They are a
58means of communicating data between multiple processes and for passing messages
59among tasks and ISRs. Message queues can contain a variable number of messages
60from 0 to an upper limit that is user defined. The maximum length of the
61message can be set on a per message queue basis.  Normally messages are sent
62and received from the message queue in FIFO order. However, messages can also
63be prioritized and a priority queue established for the passing of
64messages. Synchronization is needed when a task waits for a message to arrive
65at a queue. Also, a task may poll a queue for the arrival of a message.
66
67.. index:: mqd_t
68
69The message queue descriptor ``mqd_t`` represents the message queue. It is
70passed as an argument to all of the message queue functions.
71
72Building a Message Queue Attribute Set
73--------------------------------------
74
75The ``mq_attr`` structure is used to define the characteristics of the message
76queue.
77
78.. index:: mq_attr
79
80.. code-block:: c
81
82    typedef struct mq_attr{
83        long mq_flags;
84        long mq_maxmsg;
85        long mq_msgsize;
86        long mq_curmsgs;
87    };
88
89All of these attributes are set when the message queue is created using
90mq_open. The mq_flags field is not used in the creation of a message queue, it
91is only used by ``mq_setattr`` and ``mq_getattr``. The structure ``mq_attr`` is
92passed as an argument to ``mq_setattr`` and ``mq_getattr``.
93
94The mq_flags contain information affecting the behavior of the message
95queue. The ``O_NONBLOCK`` ``mq_flag`` is the only flag that is defined. In
96``mq_setattr``, the ``mq_flag`` can be set to dynamically change the blocking
97and non-blocking behavior of the message queue. If the non-block flag is set
98then the message queue is non-blocking, and requests to send and receive
99messages do not block waiting for resources. For a blocking message queue, a
100request to send might have to wait for an empty message queue, and a request to
101receive might have to wait for a message to arrive on the queue. Both
102``mq_maxmsg`` and ``mq_msgsize`` affect the sizing of the message
103queue. ``mq_maxmsg`` specifies how many messages the queue can hold at any one
104time. ``mq_msgsize`` specifies the size of any one message on the queue.  If
105either of these limits is exceeded, an error message results.
106
107Upon return from ``mq_getattr``, the ``mq_curmsgs`` is set according to the
108current state of the message queue. This specifies the number of messages
109currently on the queue.
110
111Notification of a Message on the Queue
112--------------------------------------
113
114Every message queue has the ability to notify one (and only one) process
115whenever the queue's state changes from empty (0 messages) to nonempty.  This
116means that the process does not have to block or constantly poll while it waits
117for a message. By calling ``mq_notify``, you can attach a notification request
118to a message queue. When a message is received by an empty queue, if there are
119no processes blocked and waiting for the message, then the queue notifies the
120requesting process of a message arrival. There is only one signal sent by the
121message queue, after that the notification request is de-registered and another
122process can attach its notification request. After receipt of a notification, a
123process must re-register if it wishes to be notified again.
124
125If there is a process blocked and waiting for the message, that process gets
126the message, and notification is not sent. It is also possible for another
127process to receive the message after the notification is sent but before the
128notified process has sent its receive request.
129
130Only one process can have a notification request attached to a message queue at
131any one time. If another process attempts to register a notification request,
132it fails. You can de-register for a message queue by passing a NULL to
133mq_notify, this removes any notification request attached to the
134queue. Whenever the message queue is closed, all notification attachments are
135removed.
136
137POSIX Interpretation Issues
138---------------------------
139
140There is one significant point of interpretation related to the RTEMS
141implementation of POSIX message queues:
142
143 | What happens to threads already blocked on a message queue when the mode
144 | of that same message queue is changed from blocking to non-blocking?
145
146The RTEMS POSIX implementation decided to unblock all waiting tasks with an
147``EAGAIN`` status just as if a non-blocking version of the same operation had
148returned unsatisfied.  This case is not discussed in the POSIX standard and
149other implementations may have chosen alternative behaviors.
150
151Operations
152==========
153
154Opening or Creating a Message Queue
155-----------------------------------
156
157If the message queue already exists, ``mq_open()`` opens it, if the message
158queue does not exist, ``mq_open()`` creates it. When a message queue is
159created, the geometry of the message queue is contained in the attribute
160structure that is passed in as an argument. This includes mq_msgsize that
161dictates the maximum size of a single message, and the mq_maxmsg that dictates
162the maximum number of messages the queue can hold at one time.  The blocking or
163non-blocking behavior of the queue can also specified.
164
165Closing a Message Queue
166-----------------------
167
168The ``mq_close()`` function is used to close the connection made to a message
169queue that was made during mq_open. The message queue itself and the messages
170on the queue are persistent and remain after the queue is closed.
171
172Removing a Message Queue
173------------------------
174
175The ``mq_unlink()`` function removes the named message queue. If the message
176queue is not open when mq_unlink is called, then the queue is immediately
177eliminated. Any messages that were on the queue are lost, and the queue can not
178be opened again. If processes have the queue open when mq_unlink is called, the
179removal of the queue is delayed until the last process using the queue has
180finished. However, the name of the message queue is removed so that no other
181process can open it.
182
183Sending a Message to a Message Queue
184------------------------------------
185
186The ``mq_send()`` function adds the message in priority order to the message
187queue. Each message has an assigned a priority. The highest priority message is
188be at the front of the queue.
189
190The maximum number of messages that a message queue may accept is specified at
191creation by the ``mq_maxmsg`` field of the attribute structure.  If this amount
192is exceeded, the behavior of the process is determined according to what
193``oflag`` was used when the message queue was opened. If the queue was opened
194with ``O_NONBLOCK`` flag set, the process does not block, and an error is
195returned. If the ``O_NONBLOCK`` flag was not set, the process does block and
196wait for space on the queue.
197
198Receiving a Message from a Message Queue
199----------------------------------------
200
201The ``mq_receive()`` function is used to receive the oldest of the highest
202priority message(s) from the message queue specified by mqdes. The messages are
203received in FIFO order within the priorities. The received message's priority
204is stored in the location referenced by the ``msg_prio``.  If the ``msg_prio``
205is a ``NULL``, the priority is discarded. The message is removed and stored in
206an area pointed to by ``msg_ptr`` whose length is of ``msg_len``. The
207``msg_len`` must be at least equal to the ``mq_msgsize`` attribute of the
208message queue.
209
210The blocking behavior of the message queue is set by ``O_NONBLOCK`` at
211``mq_open`` or by setting ``O_NONBLOCK`` in ``mq_flags`` in a call to
212``mq_setattr``. If this is a blocking queue, the process does block and wait on
213an empty queue. If this a non-blocking queue, the process does not block. Upon
214successful completion, ``mq_receive`` returns the length of the selected
215message in bytes and the message is removed from the queue.
216
217Notification of Receipt of a Message on an Empty Queue
218------------------------------------------------------
219
220The ``mq_notify()`` function registers the calling process to be notified of
221message arrival at an empty message queue. Every message queue has the ability
222to notify one (and only one) process whenever the queue's state changes from
223empty (0 messages) to nonempty. This means that the process does not have to
224block or constantly poll while it waits for a message.  By calling
225``mq_notify``, a notification request is attached to a message queue. When a
226message is received by an empty queue, if there are no processes blocked and
227waiting for the message, then the queue notifies the requesting process of a
228message arrival. There is only one signal sent by the message queue, after that
229the notification request is de-registered and another process can attach its
230notification request. After receipt of a notification, a process must
231re-register if it wishes to be notified again.
232
233If there is a process blocked and waiting for the message, that process gets
234the message, and notification is not sent. Only one process can have a
235notification request attached to a message queue at any one time. If another
236process attempts to register a notification request, it fails.  You can
237de-register for a message queue by passing a ``NULL`` to ``mq_notify``, this
238removes any notification request attached to the queue. Whenever the message
239queue is closed, all notification attachments are removed.
240
241Setting the Attributes of a Message Queue
242-----------------------------------------
243
244The ``mq_setattr()`` function is used to set attributes associated with the
245open message queue description referenced by the message queue descriptor
246specified by mqdes. The ``*omqstat`` represents the old or previous
247attributes. If ``omqstat`` is non-``NULL``, the function ``mq_setattr()``
248stores, in the location referenced by omqstat, the previous message queue
249attributes and the current queue status. These values are the same as would be
250returned by a call to ``mq_getattr()`` at that point.
251
252There is only one ``mq_attr.mq_flag`` that can be altered by this call. This is
253the flag that deals with the blocking and non-blocking behavior of the message
254queue. If the flag is set then the message queue is non-blocking, and requests
255to send or receive do not block while waiting for resources.  If the flag is
256not set, then message send and receive may involve waiting for an empty queue
257or waiting for a message to arrive.
258
259Getting the Attributes of a Message Queue
260-----------------------------------------
261
262The ``mq_getattr()`` function is used to get status information and attributes
263of the message queue associated with the message queue descriptor. The results
264are returned in the mq_attr structure referenced by the mqstat argument. All of
265these attributes are set at create time, except the blocking/non-blocking
266behavior of the message queue which can be dynamically set by using
267mq_setattr. The attribute mq_curmsg is set to reflect the number of messages on
268the queue at the time that ``mq_getattr`` was called.
269
270Directives
271==========
272
273This section details the message passing manager's directives. A subsection is
274dedicated to each of this manager's directives and describes the calling
275sequence, related constants, usage, and status codes.
276
277.. _mq_open:
278
279mq_open - Open a Message Queue
280------------------------------
281.. index:: mq_open
282.. index:: open a message queue
283
284**CALLING SEQUENCE:**
285
286.. code-block:: c
287
288    #include <mqueue.h>
289    mqd_t mq_open(
290        const char     *name,
291        int             oflag,
292        mode_t          mode,
293        struct mq_attr *attr
294    );
295
296**STATUS CODES:**
297
298.. list-table::
299 :class: rtems-table
300
301 * - ``EACCES``
302   - Either the message queue exists and the permissions requested in
303     ``oflags`` were denied, or the message does not exist and permission to
304     create one is denied.
305 * - ``EEXIST``
306   - You tried to create a message queue that already exists.
307 * - ``EINVAL``
308   - An inappropriate name was given for the message queue, or the values of
309     ``mq-maxmsg`` or ``mq_msgsize`` were less than 0.
310 * - ``ENOENT``
311   - The message queue does not exist, and you did not specify to create it.
312 * - ``EINTR``
313   - The call to mq_open was interrupted by a signal.
314 * - ``EMFILE``
315   - The process has too many files or message queues open.  This is a process
316     limit error.
317 * - ``ENFILE``
318   - The system has run out of resources to support more open message
319     queues. This is a system error.
320 * - ``ENAMETOOLONG``
321   - ``mq_name`` is too long.
322
323**DESCRIPTION:**
324
325The ``mq_open()`` function establishes the connection between a process and a
326message queue with a message queue descriptor. If the message queue already
327exists, ``mq_open`` opens it, if the message queue does not exist, ``mq_open``
328creates it. Message queues can have multiple senders and receivers. If
329``mq_open`` is successful, the function returns a message queue
330descriptor. Otherwise, the function returns a -1 and sets ``errno`` to indicate
331the error.
332
333The name of the message queue is used as an argument. For the best of
334portability, the name of the message queue should begin with a "/" and no other
335"/" should be in the name. Different systems interpret the name in different
336ways.
337
338The ``oflags`` contain information on how the message is opened if the queue
339already exists. This may be ``O_RDONLY`` for read only, ``O_WRONLY`` for write
340only, of O_RDWR, for read and write.
341
342In addition, the ``oflags`` contain information needed in the creation of a message
343queue.
344
345.. list-table::
346 :class: rtems-table
347
348 * - ``O_NONBLOCK``
349   - If the non-block flag is set then the message queue is non-blocking, and
350     requests to send and receive messages do not block waiting for
351     resources. If the flag is not set then the message queue is blocking, and
352     a request to send might have to wait for an empty message
353     queue. Similarly, a request to receive might have to wait for a message to
354     arrive on the queue.
355 * - ``O_CREAT``
356   - This call specifies that the call the mq_open is to create a new message
357     queue. In this case the mode and attribute arguments of the function call
358     are utilized. The message queue is created with a mode similar to the
359     creation of a file, read and write permission creator, group, and others.
360     The geometry of the message queue is contained in the attribute structure.
361     This includes mq_msgsize that dictates the maximum size of a single
362     message, and the mq_maxmsg that dictates the maximum number of messages
363     the queue can hold at one time. If a ``NULL`` is used in the mq_attr
364     argument, then the message queue is created with implementation defined
365     defaults.
366 * - ``O_EXCL``
367   - is always set if ``O_CREAT`` flag is set. If the message queue already
368     exists, ``O_EXCL`` causes an error message to be returned, otherwise, the
369     new message queue fails and appends to the existing one.
370
371**NOTES:**
372
373The ``mq_open()`` function does not add or remove messages from the queue.
374When a new message queue is being created, the ``mq_flag`` field of the
375attribute structure is not used.
376
377.. _mq_close:
378
379mq_close - Close a Message Queue
380--------------------------------
381.. index:: mq_close
382.. index:: close a message queue
383
384**CALLING SEQUENCE:**
385
386.. code-block:: c
387
388    #include <mqueue.h>
389    int mq_close(
390        mqd_t mqdes
391    );
392
393**STATUS CODES:**
394
395.. list-table::
396 :class: rtems-table
397
398 * - ``EINVAL``
399   - The descriptor does not represent a valid open message queue
400
401**DESCRIPTION:**
402
403The ``mq_close`` function removes the association between the message queue
404descriptor, mqdes, and its message queue. If ``mq_close()`` is successfully
405completed, the function returns a value of zero; otherwise, the function
406returns a value of -1 and sets ``errno`` to indicate the error.
407
408**NOTES:**
409
410If the process had successfully attached a notification request to the message
411queue via ``mq_notify``, this attachment is removed, and the message queue is
412available for another process to attach for notification.  ``mq_close`` has no
413effect on the contents of the message queue, all the messages that were in the
414queue remain in the queue.
415
416.. _mq_unlink:
417
418mq_unlink - Remove a Message Queue
419----------------------------------
420.. index:: mq_unlink
421.. index:: remove a message queue
422
423**CALLING SEQUENCE:**
424
425.. code-block:: c
426
427    #include <mqueue.h>
428    int mq_unlink(
429        const char *name
430    );
431
432**STATUS CODES:**
433
434.. list-table::
435 :class: rtems-table
436
437 * - ``EINVAL``
438   - The descriptor does not represent a valid message queue
439
440**DESCRIPTION:**
441
442The ``mq_unlink()`` function removes the named message queue. If the message
443queue is not open when ``mq_unlink`` is called, then the queue is immediately
444eliminated. Any messages that were on the queue are lost, and the queue can not
445be opened again. If processes have the queue open when ``mq_unlink`` is called,
446the removal of the queue is delayed until the last process using the queue has
447finished. However, the name of the message queue is removed so that no other
448process can open it. Upon successful completion, the function returns a value
449of zero. Otherwise, the named message queue is not changed by this function
450call, and the function returns a value of
451-1 and sets ``errno`` to indicate the error.
452
453**NOTES:**
454
455Calls to ``mq_open()`` to re-create the message queue may fail until the
456message queue is actually removed. However, the ``mq_unlink()`` call need not
457block until all references have been closed; it may return immediately.
458
459.. _mq_send:
460
461mq_send - Send a Message to a Message Queue
462-------------------------------------------
463.. index:: mq_send
464.. index:: send a message to a message queue
465
466**CALLING SEQUENCE:**
467
468.. code-block:: c
469
470    #include<mqueue.h>
471    int mq_send(
472        mqd_t        mqdes,
473        const char  *msg_ptr,
474        size_t       msg_len,
475        unsigned int msg_prio
476    );
477
478**STATUS CODES:**
479
480.. list-table::
481 :class: rtems-table
482
483 * - ``EBADF``
484   - The descriptor does not represent a valid message queue, or the queue was
485     opened for read only ``O_RDONLY``
486 * - ``EINVAL``
487   - The value of msg_prio was greater than the ``MQ_PRIO_MAX``.
488 * - ``EMSGSIZE``
489   - The msg_len is greater than the ``mq_msgsize`` attribute of the message
490     queue
491 * - ``EAGAIN``
492   - The message queue is non-blocking, and there is no room on the queue for
493     another message as specified by the ``mq_maxmsg``.
494 * - ``EINTR``
495   - The message queue is blocking. While the process was waiting for free
496     space on the queue, a signal arrived that interrupted the wait.
497
498**DESCRIPTION:**
499
500The ``mq_send()`` function adds the message pointed to by the argument
501``msg_ptr`` to the message queue specified by mqdes. Each message is assigned a
502priority , from 0 to ``MQ_PRIO_MAX``. ``MQ_PRIO_MAX`` is defined in
503``<limits.h>`` and must be at least 32. Messages are added to the queue in
504order of their priority. The highest priority message is at the front of the
505queue.
506
507The maximum number of messages that a message queue may accept is specified at
508creation by the ``mq_maxmsg`` field of the attribute structure.  If this amount is
509exceeded, the behavior of the process is determined according to what oflag was
510used when the message queue was opened. If the queue was opened with ``O_NONBLOCK``
511flag set, then the ``EAGAIN`` error is returned. If the ``O_NONBLOCK`` flag was not
512set, the process blocks and waits for space on the queue, unless it is
513interrupted by a signal.
514
515Upon successful completion, the ``mq_send()`` function returns a value of
516zero. Otherwise, no message is enqueued, the function returns -1, and ``errno``
517is set to indicate the error.
518
519**NOTES:**
520
521If the specified message queue is not full, ``mq_send`` inserts the message at
522the position indicated by the ``msg_prio`` argument.
523
524.. _mq_receive:
525
526mq_receive - Receive a Message from a Message Queue
527---------------------------------------------------
528.. index:: mq_receive
529.. index:: receive a message from a message queue
530
531**CALLING SEQUENCE:**
532
533.. code-block:: c
534
535    #include <mqueue.h>
536    size_t mq_receive(
537        mqd_t         mqdes,
538        char         *msg_ptr,
539        size_t        msg_len,
540        unsigned int *msg_prio
541    );
542
543**STATUS CODES:**
544
545.. list-table::
546 :class: rtems-table
547
548 * - ``EBADF``
549   - The descriptor does not represent a valid message queue, or the queue was
550     opened for write only ``O_WRONLY``
551 * - ``EMSGSIZE``
552   - The msg_len is less than the ``mq_msgsize`` attribute of the message queue
553 * - ``EAGAIN``
554   - The message queue is non-blocking, and the queue is empty
555 * - ``EINTR``
556   - The message queue is blocking. While the process was waiting for a message
557     to arrive on the queue, a signal arrived that interrupted the wait.
558
559**DESCRIPTION:**
560
561The ``mq_receive`` function is used to receive the oldest of the highest
562priority message(s) from the message queue specified by mqdes. The messages are
563received in FIFO order within the priorities. The received message's priority
564is stored in the location referenced by the ``msg_prio``.  If the ``msg_prio``
565is a ``NULL``, the priority is discarded. The message is removed and stored in
566an area pointed to by ``msg_ptr`` whose length is of ``msg_len``. The
567``msg_len`` must be at least equal to the mq_msgsize attribute of the message
568queue.
569
570The blocking behavior of the message queue is set by ``O_NONBLOCK`` at
571``mq_open`` or by setting ``O_NONBLOCK`` in ``mq_flags`` in a call to
572``mq_setattr``. If this is a blocking queue, the process blocks and waits on an
573empty queue. If this a non-blocking queue, the process does not block.
574
575Upon successful completion, ``mq_receive`` returns the length of the selected
576message in bytes and the message is removed from the queue. Otherwise, no
577message is removed from the queue, the function returns a value of -1, and sets
578``errno`` to indicate the error.
579
580**NOTES:**
581
582If the size of the buffer in bytes, specified by the ``msg_len`` argument, is
583less than the ``mq_msgsize`` attribute of the message queue, the function fails
584and returns an error
585
586.. _mq_notify:
587
588mq_notify - Notify Process that a Message is Available
589------------------------------------------------------
590.. index:: mq_notify
591.. index:: notify process that a message is available
592
593**CALLING SEQUENCE:**
594
595.. code-block:: c
596
597    #include <mqueue.h>
598    int mq_notify(
599        mqd_t                  mqdes,
600        const struct sigevent *notification
601    );
602
603**STATUS CODES:**
604
605.. list-table::
606 :class: rtems-table
607
608 * - ``EBADF``
609   - The descriptor does not refer to a valid message queue
610 * - ``EBUSY``
611   - A notification request is already attached to the queue
612
613**DESCRIPTION:**
614
615If the argument notification is not ``NULL``, this function registers the
616calling process to be notified of message arrival at an empty message queue
617associated with the specified message queue descriptor, ``mqdes``.
618
619Every message queue has the ability to notify one (and only one) process
620whenever the queue's state changes from empty (0 messages) to nonempty.  This
621means that the process does not have to block or constantly poll while it waits
622for a message. By calling ``mq_notify``, a notification request is attached to
623a message queue. When a message is received by an empty queue, if there are no
624processes blocked and waiting for the message, then the queue notifies the
625requesting process of a message arrival. There is only one signal sent by the
626message queue, after that the notification request is de-registered and another
627process can attach its notification request. After receipt of a notification, a
628process must re-register if it wishes to be notified again.
629
630If there is a process blocked and waiting for the message, that process
631gets the message, and notification is not be sent. Only one process can
632have a notification request attached to a message queue at any one time.
633If another process attempts to register a notification request, it fails.
634You can de-register for a message queue by passing a NULL to mq_notify;
635this removes any notification request attached to the queue. Whenever the
636message queue is closed, all notification attachments are removed.
637
638Upon successful completion, mq_notify returns a value of zero; otherwise, the
639function returns a value of -1 and sets ``errno`` to indicate the error.
640
641**NOTES:**
642
643It is possible for another process to receive the message after the
644notification is sent but before the notified process has sent its receive
645request.
646
647.. _mq_setattr:
648
649mq_setattr - Set Message Queue Attributes
650-----------------------------------------
651.. index:: mq_setattr
652.. index:: set message queue attributes
653
654**CALLING SEQUENCE:**
655
656.. code-block:: c
657
658    #include <mqueue.h>
659    int mq_setattr(
660        mqd_t                 mqdes,
661        const struct mq_attr *mqstat,
662        struct mq_attr       *omqstat
663    );
664
665**STATUS CODES:**
666
667.. list-table::
668 :class: rtems-table
669
670 * - ``EBADF``
671   - The message queue descriptor does not refer to a valid, open queue.
672 * - ``EINVAL``
673   - The mq_flag value is invalid.
674
675**DESCRIPTION:**
676
677The ``mq_setattr`` function is used to set attributes associated with the open
678message queue description referenced by the message queue descriptor specified
679by mqdes. The ``*omqstat`` represents the old or previous attributes. If
680``omqstat`` is non-``NULL``, the function ``mq_setattr()`` stores, in the
681location referenced by ``omqstat``, the previous message queue attributes and
682the current queue status. These values are the same as would be returned by a
683call to ``mq_getattr()`` at that point.
684
685There is only one mq_attr.mq_flag which can be altered by this call.  This is
686the flag that deals with the blocking and non-blocking behavior of the message
687queue. If the flag is set then the message queue is non-blocking, and requests
688to send or receive do not block while waiting for resources. If the flag is not
689set, then message send and receive may involve waiting for an empty queue or
690waiting for a message to arrive.
691
692Upon successful completion, the function returns a value of zero and the
693attributes of the message queue have been changed as specified.  Otherwise, the
694message queue attributes is unchanged, and the function returns a value of -1
695and sets ``errno`` to indicate the error.
696
697**NOTES:**
698
699All other fields in the ``mq_attr`` are ignored by this call.
700
701.. _mq_getattr:
702
703mq_getattr - Get Message Queue Attributes
704-----------------------------------------
705.. index:: mq_getattr
706.. index:: get message queue attributes
707
708**CALLING SEQUENCE:**
709
710.. code-block:: c
711
712    #include <mqueue.h>
713    int mq_getattr(
714        mqd_t           mqdes,
715        struct mq_attr *mqstat
716    );
717
718**STATUS CODES:**
719
720.. list-table::
721 :class: rtems-table
722
723 * - ``EBADF``
724   - The message queue descriptor does not refer to a valid, open message
725     queue.
726
727**DESCRIPTION:**
728
729The ``mqdes`` argument specifies a message queue descriptor. The ``mq_getattr``
730function is used to get status information and attributes of the message queue
731associated with the message queue descriptor. The results are returned in the
732``mq_attr`` structure referenced by the mqstat argument. All of these
733attributes are set at create time, except the blocking/non-blocking behavior of
734the message queue which can be dynamically set by using mq_setattr. The
735attribute ``mq_curmsg`` is set to reflect the number of messages on the queue
736at the time that ``mq_getattr`` was called.
737
738Upon successful completion, the ``mq_getattr`` function returns zero.
739Otherwise, the function returns -1 and sets ``errno`` to indicate the error.
740
741**NOTES:**
Note: See TracBrowser for help on using the repository browser.