source: rtems/cpukit/posix/src/mqueuesendsupp.c @ 3bacb250

4.104.115
Last change on this file since 3bacb250 was b1dbfd7, checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/03/09 at 10:10:57

Eliminate TRUE/FALSE.

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