source: rtems/cpukit/posix/src/mqueuerecvsupp.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/**
2 * @file
3 *
4 * @brief POSIX Message Queue Receive Support
5 * @ingroup POSIX_MQUEUE_P Message Queues Private Support Information
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2011.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
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/mqueueimpl.h>
33#include <rtems/posix/time.h>
34
35/*
36 *  _POSIX_Message_queue_Receive_support
37 *
38 *  NOTE: XXX Document how size, priority, length, and the buffer go
39 *        through the layers.
40 */
41
42ssize_t _POSIX_Message_queue_Receive_support(
43  mqd_t               mqdes,
44  char               *msg_ptr,
45  size_t              msg_len,
46  unsigned int       *msg_prio,
47  bool                wait,
48  Watchdog_Interval   timeout
49)
50{
51  POSIX_Message_queue_Control     *the_mq;
52  POSIX_Message_queue_Control_fd  *the_mq_fd;
53  Objects_Locations                location;
54  size_t                           length_out;
55  bool                             do_wait;
56  Thread_Control                  *executing;
57
58  the_mq_fd = _POSIX_Message_queue_Get_fd( mqdes, &location );
59  switch ( location ) {
60
61    case OBJECTS_LOCAL:
62      if ( (the_mq_fd->oflag & O_ACCMODE) == O_WRONLY ) {
63        _Objects_Put( &the_mq_fd->Object );
64        rtems_set_errno_and_return_minus_one( EBADF );
65      }
66
67      the_mq = the_mq_fd->Queue;
68
69      if ( msg_len < the_mq->Message_queue.maximum_message_size ) {
70        _Objects_Put( &the_mq_fd->Object );
71        rtems_set_errno_and_return_minus_one( EMSGSIZE );
72      }
73
74      /*
75       *  Now if something goes wrong, we return a "length" of -1
76       *  to indicate an error.
77       */
78
79      length_out = -1;
80
81      /*
82       *  A timed receive with a bad time will do a poll regardless.
83       */
84      if ( wait )
85        do_wait = (the_mq_fd->oflag & O_NONBLOCK) ? false : true;
86      else
87        do_wait = wait;
88
89      /*
90       *  Now perform the actual message receive
91       */
92      executing = _Thread_Executing;
93      _CORE_message_queue_Seize(
94        &the_mq->Message_queue,
95        executing,
96        mqdes,
97        msg_ptr,
98        &length_out,
99        do_wait,
100        timeout
101      );
102
103      _Objects_Put( &the_mq_fd->Object );
104      if (msg_prio) {
105        *msg_prio = _POSIX_Message_queue_Priority_from_core(
106             executing->Wait.count
107          );
108      }
109
110      if ( !executing->Wait.return_code )
111        return length_out;
112
113      rtems_set_errno_and_return_minus_one(
114        _POSIX_Message_queue_Translate_core_message_queue_return_code(
115          executing->Wait.return_code
116        )
117      );
118
119#if defined(RTEMS_MULTIPROCESSING)
120    case OBJECTS_REMOTE:
121#endif
122    case OBJECTS_ERROR:
123      break;
124  }
125
126  rtems_set_errno_and_return_minus_one( EBADF );
127}
Note: See TracBrowser for help on using the repository browser.