2 #include "ace/Min_Max.h"
3 #include "ace/OS_NS_stropts.h"
4 #include "ace/Truncate.h"
6 #if !defined (ACE_HAS_STREAM_PIPES)
7 #include "ace/OS_NS_unistd.h"
10 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
13 ACE_FIFO_Recv_Msg::recv (ACE_Str_Buf &recv_msg)
15 ACE_TRACE ("ACE_FIFO_Recv_Msg::recv");
16 #if defined (ACE_HAS_STREAM_PIPES)
18 if (ACE_OS::getmsg (this->get_handle (),
29 #else /* Do the ol' 2-read trick... */
30 if (ACE_OS::read (this->get_handle (),
31 (char *) &recv_msg.len,
32 sizeof recv_msg.len) != (ssize_t) sizeof recv_msg.len)
38 size_t remaining = static_cast<size_t> (recv_msg.len);
39 size_t requested = static_cast<size_t> (recv_msg.maxlen);
40 ssize_t recv_len = ACE_OS::read (this->get_handle (),
41 (char *) recv_msg.buf,
42 ACE_MIN (remaining, requested));
49 // Tell caller what's really in the buffer.
50 recv_msg.len = static_cast<int> (recv_len);
52 // If there are more bytes remaining in the message, read them and
53 // throw them away. Leaving them in the FIFO would make it difficult
54 // to find the start of the next message in the fifo.
55 // Since the ACE_HAS_STREAM_PIPES version of this method doesn't
56 // return getmsg()'s indication of "data remaining", don't worry about
57 // saving the indication here either to read the remainder later.
58 size_t total_msg_size = remaining;
59 remaining -= recv_len;
63 const size_t throw_away = 1024;
64 char dev_null[throw_away];
65 recv_len = ACE_OS::read (this->get_handle (),
67 ACE_MIN (remaining, throw_away));
74 remaining -= recv_len;
77 return ACE_Utils::truncate_cast<ssize_t> (total_msg_size);
79 #endif /* ACE_HAS_STREAM_PIPES */
83 ACE_FIFO_Recv_Msg::recv (void *buf, size_t max_len)
85 ACE_TRACE ("ACE_FIFO_Recv_Msg::recv");
86 ACE_Str_Buf recv_msg ((char *) buf, 0, static_cast<int> (max_len));
88 return this->recv (recv_msg);
91 #if defined (ACE_HAS_STREAM_PIPES)
93 ACE_FIFO_Recv_Msg::recv (ACE_Str_Buf *data,
97 ACE_TRACE ("ACE_FIFO_Recv_Msg::recv");
98 if (ACE_OS::getmsg (this->get_handle (),
107 return (cntl == 0 ? 0 : cntl->len) + (data == 0 ? 0 : data->len);
112 ACE_FIFO_Recv_Msg::recv (int *band,
117 ACE_TRACE ("ACE_FIFO_Recv_Msg::recv");
119 if (ACE_OS::getpmsg (this->get_handle (),
129 return (cntl == 0 ? 0 : cntl->len) + (data == 0 ? 0 : data->len);
132 #endif /* ACE_HAS_STREAM_PIPES */
134 ACE_END_VERSIONED_NAMESPACE_DECL