source: rtems/cpukit/posix/src/mqueuetimedreceive.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/**
2 * @file
3 *
4 * @brief Receive Message from Message Queue
5 * @ingroup POSIXAPI
6 */
7
8/*
9 *  NOTE:  The structure of the routines is identical to that of POSIX
10 *         Message_queues to leave the option of having unnamed message
11 *         queues at a future date.  They are currently not part of the
12 *         POSIX standard but unnamed message_queues are.  This is also
13 *         the reason for the apparently unnecessary tracking of
14 *         the process_shared attribute.  [In addition to the fact that
15 *         it would be trivial to add pshared to the mq_attr structure
16 *         and have process private message queues.]
17 *
18 *         This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
19 *         time.
20 */
21
22/*
23 *  COPYRIGHT (c) 1989-2008.
24 *  On-Line Applications Research Corporation (OAR).
25 *
26 *  The license and distribution terms for this file may be
27 *  found in the file LICENSE in this distribution or at
28 *  http://www.rtems.org/license/LICENSE.
29 */
30
31#if HAVE_CONFIG_H
32#include "config.h"
33#endif
34
35#include <stdarg.h>
36
37#include <pthread.h>
38#include <limits.h>
39#include <errno.h>
40#include <fcntl.h>
41#include <mqueue.h>
42
43#include <rtems/system.h>
44#include <rtems/score/watchdog.h>
45#include <rtems/seterr.h>
46#include <rtems/posix/mqueueimpl.h>
47#include <rtems/posix/time.h>
48
49/*
50 *  15.2.5 Receive a Message From a Message Queue, P1003.1b-1993, p. 279
51 *
52 *  NOTE: P1003.4b/D8, p. 45 adds mq_timedreceive().
53 */
54
55ssize_t mq_timedreceive(
56  mqd_t                  mqdes,
57  char                  *__restrict msg_ptr,
58  size_t                 msg_len,
59  unsigned int          *__restrict msg_prio,
60  const struct timespec *__restrict abstime
61)
62{
63  Watchdog_Interval                            ticks;
64  bool                                         do_wait = true;
65  POSIX_Absolute_timeout_conversion_results_t  status;
66
67  /*
68   *  POSIX requires that blocking calls with timeouts that take
69   *  an absolute timeout must ignore issues with the absolute
70   *  time provided if the operation would otherwise succeed.
71   *  So we check the abstime provided, and hold on to whether it
72   *  is valid or not.  If it isn't correct and in the future,
73   *  then we do a polling operation and convert the UNSATISFIED
74   *  status into the appropriate error.
75   *
76   *  If the status is POSIX_ABSOLUTE_TIMEOUT_INVALID,
77   *  POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST, or POSIX_ABSOLUTE_TIMEOUT_IS_NOW,
78   *  then we should not wait.
79   */
80  status = _POSIX_Absolute_timeout_to_ticks( abstime, &ticks );
81  if ( status != POSIX_ABSOLUTE_TIMEOUT_IS_IN_FUTURE )
82    do_wait = false;
83
84  return _POSIX_Message_queue_Receive_support(
85    mqdes,
86    msg_ptr,
87    msg_len,
88    msg_prio,
89    do_wait,
90    ticks
91  );
92}
Note: See TracBrowser for help on using the repository browser.