[4dc89814] | 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 |
---|
[874297f3] | 5 | * POSIX standard but unnamed message_queues are. This is also |
---|
| 6 | * the reason for the apparently unnecessary tracking of |
---|
[4dc89814] | 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 | * |
---|
[6a0898b] | 14 | * COPYRIGHT (c) 1989-2008. |
---|
[feaa007] | 15 | * On-Line Applications Research Corporation (OAR). |
---|
| 16 | * |
---|
| 17 | * The license and distribution terms for this file may be |
---|
| 18 | * found in the file LICENSE in this distribution or at |
---|
| 19 | * http://www.rtems.com/license/LICENSE. |
---|
| 20 | * |
---|
[4dc89814] | 21 | * $Id$ |
---|
| 22 | */ |
---|
| 23 | |
---|
[f42b726] | 24 | #if HAVE_CONFIG_H |
---|
| 25 | #include "config.h" |
---|
| 26 | #endif |
---|
| 27 | |
---|
[4dc89814] | 28 | #include <stdarg.h> |
---|
| 29 | |
---|
| 30 | #include <pthread.h> |
---|
| 31 | #include <limits.h> |
---|
| 32 | #include <errno.h> |
---|
| 33 | #include <fcntl.h> |
---|
| 34 | #include <mqueue.h> |
---|
| 35 | |
---|
| 36 | #include <rtems/system.h> |
---|
| 37 | #include <rtems/score/watchdog.h> |
---|
[188c82b] | 38 | #include <rtems/seterr.h> |
---|
[4dc89814] | 39 | #include <rtems/posix/mqueue.h> |
---|
| 40 | #include <rtems/posix/time.h> |
---|
| 41 | |
---|
[6a0898b] | 42 | /* |
---|
[4dc89814] | 43 | * _POSIX_Message_queue_Receive_support |
---|
[68b05694] | 44 | * |
---|
| 45 | * NOTE: XXX Document how size, priority, length, and the buffer go |
---|
| 46 | * through the layers. |
---|
[4dc89814] | 47 | */ |
---|
[874297f3] | 48 | |
---|
[4dc89814] | 49 | ssize_t _POSIX_Message_queue_Receive_support( |
---|
| 50 | mqd_t mqdes, |
---|
| 51 | char *msg_ptr, |
---|
| 52 | size_t msg_len, |
---|
| 53 | unsigned int *msg_prio, |
---|
[f8437c8] | 54 | bool wait, |
---|
[4dc89814] | 55 | Watchdog_Interval timeout |
---|
| 56 | ) |
---|
| 57 | { |
---|
[53092d1] | 58 | POSIX_Message_queue_Control *the_mq; |
---|
| 59 | POSIX_Message_queue_Control_fd *the_mq_fd; |
---|
| 60 | Objects_Locations location; |
---|
[f4e0118] | 61 | size_t length_out; |
---|
[f8437c8] | 62 | bool do_wait; |
---|
[874297f3] | 63 | |
---|
[53092d1] | 64 | the_mq_fd = _POSIX_Message_queue_Get_fd( mqdes, &location ); |
---|
[4dc89814] | 65 | switch ( location ) { |
---|
[860c34e] | 66 | |
---|
[4dc89814] | 67 | case OBJECTS_LOCAL: |
---|
[53092d1] | 68 | if ( (the_mq_fd->oflag & O_ACCMODE) == O_WRONLY ) { |
---|
[fcd0c90] | 69 | _Thread_Enable_dispatch(); |
---|
[e180a77e] | 70 | rtems_set_errno_and_return_minus_one( EBADF ); |
---|
[fcd0c90] | 71 | } |
---|
| 72 | |
---|
[53092d1] | 73 | the_mq = the_mq_fd->Queue; |
---|
| 74 | |
---|
[68b05694] | 75 | if ( msg_len < the_mq->Message_queue.maximum_message_size ) { |
---|
| 76 | _Thread_Enable_dispatch(); |
---|
[e180a77e] | 77 | rtems_set_errno_and_return_minus_one( EMSGSIZE ); |
---|
[68b05694] | 78 | } |
---|
[874297f3] | 79 | |
---|
[68b05694] | 80 | /* |
---|
| 81 | * Now if something goes wrong, we return a "length" of -1 |
---|
| 82 | * to indicate an error. |
---|
| 83 | */ |
---|
| 84 | |
---|
| 85 | length_out = -1; |
---|
| 86 | |
---|
[6a0898b] | 87 | /* |
---|
| 88 | * A timed receive with a bad time will do a poll regardless. |
---|
| 89 | */ |
---|
| 90 | if ( wait ) |
---|
[b1dbfd7] | 91 | do_wait = (the_mq_fd->oflag & O_NONBLOCK) ? false : true; |
---|
[6a0898b] | 92 | else |
---|
| 93 | do_wait = wait; |
---|
| 94 | |
---|
| 95 | /* |
---|
| 96 | * Now perform the actual message receive |
---|
| 97 | */ |
---|
[4dc89814] | 98 | _CORE_message_queue_Seize( |
---|
| 99 | &the_mq->Message_queue, |
---|
| 100 | mqdes, |
---|
| 101 | msg_ptr, |
---|
| 102 | &length_out, |
---|
[6a0898b] | 103 | do_wait, |
---|
[4dc89814] | 104 | timeout |
---|
| 105 | ); |
---|
[874297f3] | 106 | |
---|
[4dc89814] | 107 | _Thread_Enable_dispatch(); |
---|
[68b05694] | 108 | *msg_prio = |
---|
| 109 | _POSIX_Message_queue_Priority_from_core(_Thread_Executing->Wait.count); |
---|
| 110 | |
---|
| 111 | if ( !_Thread_Executing->Wait.return_code ) |
---|
[4dc89814] | 112 | return length_out; |
---|
[68b05694] | 113 | |
---|
[e180a77e] | 114 | rtems_set_errno_and_return_minus_one( |
---|
[68b05694] | 115 | _POSIX_Message_queue_Translate_core_message_queue_return_code( |
---|
| 116 | _Thread_Executing->Wait.return_code |
---|
| 117 | ) |
---|
| 118 | ); |
---|
[860c34e] | 119 | |
---|
| 120 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 121 | case OBJECTS_REMOTE: |
---|
| 122 | #endif |
---|
| 123 | case OBJECTS_ERROR: |
---|
| 124 | break; |
---|
[4dc89814] | 125 | } |
---|
[860c34e] | 126 | |
---|
| 127 | rtems_set_errno_and_return_minus_one( EBADF ); |
---|
[4dc89814] | 128 | } |
---|