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 | * $Id$ |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <stdarg.h> |
---|
22 | |
---|
23 | #include <pthread.h> |
---|
24 | #include <limits.h> |
---|
25 | #include <errno.h> |
---|
26 | #include <fcntl.h> |
---|
27 | #include <mqueue.h> |
---|
28 | |
---|
29 | #include <rtems/system.h> |
---|
30 | #include <rtems/score/watchdog.h> |
---|
31 | #include <rtems/seterr.h> |
---|
32 | #include <rtems/posix/mqueue.h> |
---|
33 | #include <rtems/posix/time.h> |
---|
34 | |
---|
35 | |
---|
36 | /*PAGE |
---|
37 | * |
---|
38 | * _POSIX_Message_queue_Send_support |
---|
39 | */ |
---|
40 | |
---|
41 | int _POSIX_Message_queue_Send_support( |
---|
42 | mqd_t mqdes, |
---|
43 | const char *msg_ptr, |
---|
44 | unsigned32 msg_len, |
---|
45 | unsigned32 msg_prio, |
---|
46 | Watchdog_Interval timeout |
---|
47 | ) |
---|
48 | { |
---|
49 | register POSIX_Message_queue_Control *the_mq; |
---|
50 | Objects_Locations location; |
---|
51 | CORE_message_queue_Status msg_status; |
---|
52 | |
---|
53 | /* |
---|
54 | * Validate the priority. |
---|
55 | * XXX - Do not validate msg_prio is not less than 0. |
---|
56 | */ |
---|
57 | |
---|
58 | if ( msg_prio > MQ_PRIO_MAX ) |
---|
59 | set_errno_and_return_minus_one( EINVAL ); |
---|
60 | |
---|
61 | the_mq = _POSIX_Message_queue_Get( mqdes, &location ); |
---|
62 | |
---|
63 | switch ( location ) { |
---|
64 | case OBJECTS_ERROR: |
---|
65 | set_errno_and_return_minus_one( EBADF ); |
---|
66 | |
---|
67 | case OBJECTS_REMOTE: |
---|
68 | _Thread_Dispatch(); |
---|
69 | return POSIX_MP_NOT_IMPLEMENTED(); |
---|
70 | set_errno_and_return_minus_one( EINVAL ); |
---|
71 | |
---|
72 | case OBJECTS_LOCAL: |
---|
73 | if ( (the_mq->oflag & O_ACCMODE) == O_RDONLY ) { |
---|
74 | _Thread_Enable_dispatch(); |
---|
75 | set_errno_and_return_minus_one( EBADF ); |
---|
76 | } |
---|
77 | |
---|
78 | msg_status = _CORE_message_queue_Submit( |
---|
79 | &the_mq->Message_queue, |
---|
80 | (void *) msg_ptr, |
---|
81 | msg_len, |
---|
82 | mqdes, /* mqd_t is an object id */ |
---|
83 | #if defined(RTEMS_MULTIPROCESSING) |
---|
84 | NULL, /* XXX _POSIX_Message_queue_Core_message_queue_mp_support*/ |
---|
85 | #else |
---|
86 | NULL, |
---|
87 | #endif |
---|
88 | _POSIX_Message_queue_Priority_to_core( msg_prio ), |
---|
89 | (the_mq->oflag & O_NONBLOCK) ? FALSE : TRUE, |
---|
90 | timeout /* no timeout */ |
---|
91 | ); |
---|
92 | |
---|
93 | _Thread_Enable_dispatch(); |
---|
94 | |
---|
95 | /* |
---|
96 | * If we had to block, then this is where the task returns |
---|
97 | * after it wakes up. The returned status is correct for |
---|
98 | * non-blocking operations but if we blocked, then we need |
---|
99 | * to look at the status in our TCB. |
---|
100 | */ |
---|
101 | |
---|
102 | if ( msg_status == CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_WAIT ) |
---|
103 | msg_status = _Thread_Executing->Wait.return_code; |
---|
104 | |
---|
105 | if ( !msg_status ) |
---|
106 | return msg_status; |
---|
107 | |
---|
108 | set_errno_and_return_minus_one( |
---|
109 | _POSIX_Message_queue_Translate_core_message_queue_return_code( |
---|
110 | msg_status |
---|
111 | ) |
---|
112 | ); |
---|
113 | } |
---|
114 | return POSIX_BOTTOM_REACHED(); |
---|
115 | } |
---|