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 | #include <stdarg.h> |
---|
18 | |
---|
19 | #include <pthread.h> |
---|
20 | #include <limits.h> |
---|
21 | #include <errno.h> |
---|
22 | #include <fcntl.h> |
---|
23 | #include <mqueue.h> |
---|
24 | |
---|
25 | #include <rtems/system.h> |
---|
26 | #include <rtems/score/watchdog.h> |
---|
27 | #include <rtems/posix/seterr.h> |
---|
28 | #include <rtems/posix/mqueue.h> |
---|
29 | #include <rtems/posix/time.h> |
---|
30 | |
---|
31 | /*PAGE |
---|
32 | * |
---|
33 | * _POSIX_Message_queue_Receive_support |
---|
34 | */ |
---|
35 | |
---|
36 | /* XXX be careful ... watch the size going through all the layers ... */ |
---|
37 | |
---|
38 | ssize_t _POSIX_Message_queue_Receive_support( |
---|
39 | mqd_t mqdes, |
---|
40 | char *msg_ptr, |
---|
41 | size_t msg_len, |
---|
42 | unsigned int *msg_prio, |
---|
43 | Watchdog_Interval timeout |
---|
44 | ) |
---|
45 | { |
---|
46 | register POSIX_Message_queue_Control *the_mq; |
---|
47 | Objects_Locations location; |
---|
48 | unsigned32 status = 0; |
---|
49 | unsigned32 length_out; |
---|
50 | CORE_message_queue_Submit_types core_priority; |
---|
51 | |
---|
52 | the_mq = _POSIX_Message_queue_Get( mqdes, &location ); |
---|
53 | switch ( location ) { |
---|
54 | case OBJECTS_ERROR: |
---|
55 | set_errno_and_return_minus_one( EINVAL ); |
---|
56 | case OBJECTS_REMOTE: |
---|
57 | _Thread_Dispatch(); |
---|
58 | return POSIX_MP_NOT_IMPLEMENTED(); |
---|
59 | set_errno_and_return_minus_one( EINVAL ); |
---|
60 | case OBJECTS_LOCAL: |
---|
61 | if ( (the_mq->oflag & O_ACCMODE) == O_WRONLY ) { |
---|
62 | _Thread_Enable_dispatch(); |
---|
63 | set_errno_and_return_minus_one( EBADF ); |
---|
64 | } |
---|
65 | |
---|
66 | /* XXX need to define the options argument to this */ |
---|
67 | length_out = msg_len; |
---|
68 | _CORE_message_queue_Seize( |
---|
69 | &the_mq->Message_queue, |
---|
70 | mqdes, |
---|
71 | msg_ptr, |
---|
72 | &length_out, |
---|
73 | the_mq->blocking, |
---|
74 | &core_priority, |
---|
75 | timeout |
---|
76 | ); |
---|
77 | |
---|
78 | *msg_prio = _POSIX_Message_queue_Priority_from_core( core_priority ); |
---|
79 | |
---|
80 | /* XXX convert message priority from core to POSIX */ |
---|
81 | _Thread_Enable_dispatch(); |
---|
82 | *msg_prio = _Thread_Executing->Wait.count; |
---|
83 | if ( !status ) |
---|
84 | return length_out; |
---|
85 | /* XXX --- the return codes gotta be looked at .. fix this */ |
---|
86 | return _Thread_Executing->Wait.return_code; |
---|
87 | } |
---|
88 | return POSIX_BOTTOM_REACHED(); |
---|
89 | } |
---|
90 | |
---|