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