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

4.115
Last change on this file since eb08acf was eb08acf, checked in by Mathew Kallada <matkallada@…>, on 12/15/12 at 20:41:05

posix: Doxygen Enhancement Task #8

http://www.google-melange.com/gci/task/view/google/gci2012/8003213

  • Property mode set to 100644
File size: 2.9 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.com/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/mqueue.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
57  the_mq_fd = _POSIX_Message_queue_Get_fd( mqdes, &location );
58  switch ( location ) {
59
60    case OBJECTS_LOCAL:
61      if ( (the_mq_fd->oflag & O_ACCMODE) == O_WRONLY ) {
62        _Thread_Enable_dispatch();
63        rtems_set_errno_and_return_minus_one( EBADF );
64      }
65
66      the_mq = the_mq_fd->Queue;
67
68      if ( msg_len < the_mq->Message_queue.maximum_message_size ) {
69        _Thread_Enable_dispatch();
70        rtems_set_errno_and_return_minus_one( EMSGSIZE );
71      }
72
73      /*
74       *  Now if something goes wrong, we return a "length" of -1
75       *  to indicate an error.
76       */
77
78      length_out = -1;
79
80      /*
81       *  A timed receive with a bad time will do a poll regardless.
82       */
83      if ( wait )
84        do_wait = (the_mq_fd->oflag & O_NONBLOCK) ? false : true;
85      else
86        do_wait = wait;
87
88      /*
89       *  Now perform the actual message receive
90       */
91      _CORE_message_queue_Seize(
92        &the_mq->Message_queue,
93        mqdes,
94        msg_ptr,
95        &length_out,
96        do_wait,
97        timeout
98      );
99
100      _Thread_Enable_dispatch();
101      if (msg_prio) {
102        *msg_prio = _POSIX_Message_queue_Priority_from_core(
103             _Thread_Executing->Wait.count
104          );
105      }
106
107      if ( !_Thread_Executing->Wait.return_code )
108        return length_out;
109
110      rtems_set_errno_and_return_minus_one(
111        _POSIX_Message_queue_Translate_core_message_queue_return_code(
112          _Thread_Executing->Wait.return_code
113        )
114      );
115
116#if defined(RTEMS_MULTIPROCESSING)
117    case OBJECTS_REMOTE:
118#endif
119    case OBJECTS_ERROR:
120      break;
121  }
122
123  rtems_set_errno_and_return_minus_one( EBADF );
124}
Note: See TracBrowser for help on using the repository browser.