3 // $Id: FIFO_Recv_Msg.inl 82559 2008-08-07 20:23:07Z parsons $
5 #include "ace/Min_Max.h"
6 #include "ace/OS_NS_stropts.h"
7 #include "ace/Truncate.h"
9 #if !defined (ACE_HAS_STREAM_PIPES)
10 #include "ace/OS_NS_unistd.h"
13 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
16 ACE_FIFO_Recv_Msg::recv (ACE_Str_Buf &recv_msg)
18 ACE_TRACE ("ACE_FIFO_Recv_Msg::recv");
19 #if defined (ACE_HAS_STREAM_PIPES)
21 if (ACE_OS::getmsg (this->get_handle (),
32 #else /* Do the ol' 2-read trick... */
33 if (ACE_OS::read (this->get_handle (),
34 (char *) &recv_msg.len,
35 sizeof recv_msg.len) != sizeof recv_msg.len)
41 size_t remaining = static_cast<size_t> (recv_msg.len);
42 size_t requested = static_cast<size_t> (recv_msg.maxlen);
43 ssize_t recv_len = ACE_OS::read (this->get_handle (),
44 (char *) recv_msg.buf,
45 ACE_MIN (remaining, requested));
52 // Tell caller what's really in the buffer.
53 recv_msg.len = static_cast<int> (recv_len);
55 // If there are more bytes remaining in the message, read them and
56 // throw them away. Leaving them in the FIFO would make it difficult
57 // to find the start of the next message in the fifo.
58 // Since the ACE_HAS_STREAM_PIPES version of this method doesn't
59 // return getmsg()'s indication of "data remaining", don't worry about
60 // saving the indication here either to read the remainder later.
61 size_t total_msg_size = remaining;
62 remaining -= recv_len;
66 const size_t throw_away = 1024;
67 char dev_null[throw_away];
68 recv_len = ACE_OS::read (this->get_handle (),
70 ACE_MIN (remaining, throw_away));
77 remaining -= recv_len;
80 return ACE_Utils::truncate_cast<ssize_t> (total_msg_size);
82 #endif /* ACE_HAS_STREAM_PIPES */
86 ACE_FIFO_Recv_Msg::recv (void *buf, size_t max_len)
88 ACE_TRACE ("ACE_FIFO_Recv_Msg::recv");
89 ACE_Str_Buf recv_msg ((char *) buf, 0, static_cast<int> (max_len));
91 return this->recv (recv_msg);
94 #if defined (ACE_HAS_STREAM_PIPES)
96 ACE_FIFO_Recv_Msg::recv (ACE_Str_Buf *data,
100 ACE_TRACE ("ACE_FIFO_Recv_Msg::recv");
101 if (ACE_OS::getmsg (this->get_handle (),
110 return (cntl == 0 ? 0 : cntl->len) + (data == 0 ? 0 : data->len);
115 ACE_FIFO_Recv_Msg::recv (int *band,
120 ACE_TRACE ("ACE_FIFO_Recv_Msg::recv");
122 if (ACE_OS::getpmsg (this->get_handle (),
132 return (cntl == 0 ? 0 : cntl->len) + (data == 0 ? 0 : data->len);
135 #endif /* ACE_HAS_STREAM_PIPES */
137 ACE_END_VERSIONED_NAMESPACE_DECL