source: rtems/cpukit/posix/src/mqueuesendsupp.c @ 5cb175bb

4.115
Last change on this file since 5cb175bb was 5cb175bb, checked in by Joel Sherrill <joel.sherrill@…>, on 01/10/13 at 19:22:31

cpukit/posix: Doxygen group is POSIXAPI

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/**
2 * @file
3 *
4 * @brief POSIX Message Queue and Send Support
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 *  COPYRIGHT (c) 1989-2008.
22 *  On-Line Applications Research Corporation (OAR).
23 *
24 *  The license and distribution terms for this file may be
25 *  found in the file LICENSE in this distribution or at
26 *  http://www.rtems.com/license/LICENSE.
27 */
28
29#if HAVE_CONFIG_H
30#include "config.h"
31#endif
32
33#include <stdarg.h>
34
35#include <pthread.h>
36#include <limits.h>
37#include <errno.h>
38#include <fcntl.h>
39#include <mqueue.h>
40
41#include <rtems/system.h>
42#include <rtems/score/watchdog.h>
43#include <rtems/seterr.h>
44#include <rtems/posix/mqueue.h>
45#include <rtems/posix/time.h>
46
47
48/*
49 *  _POSIX_Message_queue_Send_support
50 */
51
52int _POSIX_Message_queue_Send_support(
53  mqd_t               mqdes,
54  const char         *msg_ptr,
55  size_t              msg_len,
56  unsigned int        msg_prio,
57  bool                wait,
58  Watchdog_Interval   timeout
59)
60{
61  POSIX_Message_queue_Control    *the_mq;
62  POSIX_Message_queue_Control_fd *the_mq_fd;
63  Objects_Locations               location;
64  CORE_message_queue_Status       msg_status;
65  bool                            do_wait;
66
67  /*
68   * Validate the priority.
69   * XXX - Do not validate msg_prio is not less than 0.
70   */
71
72  if ( msg_prio > MQ_PRIO_MAX )
73    rtems_set_errno_and_return_minus_one( EINVAL );
74
75  the_mq_fd = _POSIX_Message_queue_Get_fd( mqdes, &location );
76  switch ( location ) {
77
78    case OBJECTS_LOCAL:
79      if ( (the_mq_fd->oflag & O_ACCMODE) == O_RDONLY ) {
80        _Thread_Enable_dispatch();
81        rtems_set_errno_and_return_minus_one( EBADF );
82      }
83
84      the_mq = the_mq_fd->Queue;
85
86      /*
87       *  A timed receive with a bad time will do a poll regardless.
88       */
89      if ( wait )
90        do_wait = (the_mq_fd->oflag & O_NONBLOCK) ? false : true;
91      else
92        do_wait = wait;
93
94      /*
95       *  Now perform the actual message receive
96       */
97      msg_status = _CORE_message_queue_Submit(
98        &the_mq->Message_queue,
99        msg_ptr,
100        msg_len,
101        mqdes,      /* mqd_t is an object id */
102        NULL,
103        _POSIX_Message_queue_Priority_to_core( msg_prio ),
104        do_wait,
105        timeout    /* no timeout */
106      );
107
108      _Thread_Enable_dispatch();
109
110      /*
111       *  If we had to block, then this is where the task returns
112       *  after it wakes up.  The returned status is correct for
113       *  non-blocking operations but if we blocked, then we need
114       *  to look at the status in our TCB.
115       */
116
117      if ( msg_status == CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_WAIT )
118        msg_status = _Thread_Executing->Wait.return_code;
119
120      if ( !msg_status )
121        return msg_status;
122
123      rtems_set_errno_and_return_minus_one(
124        _POSIX_Message_queue_Translate_core_message_queue_return_code(
125          msg_status
126        )
127      );
128
129#if defined(RTEMS_MULTIPROCESSING)
130    case OBJECTS_REMOTE:
131#endif
132    case OBJECTS_ERROR:
133      break;
134  }
135
136  rtems_set_errno_and_return_minus_one( EBADF );
137}
Note: See TracBrowser for help on using the repository browser.