source: rtems/cpukit/posix/src/mqueuesendsupp.c @ 6e5da272

Last change on this file since 6e5da272 was 6e5da272, checked in by Ralf Corsepius <ralf.corsepius@…>, on Feb 5, 2007 at 6:06:40 PM

Use size_t for sizes.

  • Property mode set to 100644
File size: 3.2 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 *  $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
41int _POSIX_Message_queue_Send_support(
42  mqd_t               mqdes,
43  const char         *msg_ptr,
44  size_t              msg_len,
45  uint32_t            msg_prio,
46  Watchdog_Interval   timeout
47)
48{
49  POSIX_Message_queue_Control    *the_mq;
50  POSIX_Message_queue_Control_fd *the_mq_fd;
51  Objects_Locations               location;
52  CORE_message_queue_Status       msg_status;
53
54  /*
55   * Validate the priority.
56   * XXX - Do not validate msg_prio is not less than 0.
57   */
58
59  if ( msg_prio > MQ_PRIO_MAX )
60    rtems_set_errno_and_return_minus_one( EINVAL );
61
62  the_mq_fd = _POSIX_Message_queue_Get_fd( mqdes, &location );
63  switch ( location ) {
64    case OBJECTS_ERROR:
65      rtems_set_errno_and_return_minus_one( EBADF );
66
67    case OBJECTS_REMOTE:
68      _Thread_Dispatch();
69      return POSIX_MP_NOT_IMPLEMENTED();
70      rtems_set_errno_and_return_minus_one( EINVAL );
71
72    case OBJECTS_LOCAL:
73      if ( (the_mq_fd->oflag & O_ACCMODE) == O_RDONLY ) {
74        _Thread_Enable_dispatch();
75        rtems_set_errno_and_return_minus_one( EBADF );
76      }
77
78      the_mq = the_mq_fd->Queue;
79
80      msg_status = _CORE_message_queue_Submit(
81        &the_mq->Message_queue,
82        (void *) msg_ptr,
83        msg_len,
84        mqdes,      /* mqd_t is an object id */
85#if defined(RTEMS_MULTIPROCESSING)
86        NULL,      /* XXX _POSIX_Message_queue_Core_message_queue_mp_support*/
87#else
88        NULL,
89#endif
90        _POSIX_Message_queue_Priority_to_core( msg_prio ),
91         (the_mq_fd->oflag & O_NONBLOCK) ? FALSE : TRUE,
92        timeout    /* no timeout */
93      );
94
95      _Thread_Enable_dispatch();
96
97      /*
98       *  If we had to block, then this is where the task returns
99       *  after it wakes up.  The returned status is correct for
100       *  non-blocking operations but if we blocked, then we need
101       *  to look at the status in our TCB.
102       */
103
104      if ( msg_status == CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_WAIT )
105        msg_status = _Thread_Executing->Wait.return_code;
106
107      if ( !msg_status )
108        return msg_status;
109
110      rtems_set_errno_and_return_minus_one(
111        _POSIX_Message_queue_Translate_core_message_queue_return_code(
112          msg_status
113        )
114      );
115  }
116  return POSIX_BOTTOM_REACHED();
117}
Note: See TracBrowser for help on using the repository browser.