00001
00002
00003
00004
00005 #include "ace/Min_Max.h"
00006 #include "ace/OS_NS_stropts.h"
00007
00008 #if !defined (ACE_HAS_STREAM_PIPES)
00009 #include "ace/OS_NS_unistd.h"
00010 #endif
00011
00012 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00013
00014 ACE_INLINE ssize_t
00015 ACE_FIFO_Recv_Msg::recv (ACE_Str_Buf &recv_msg)
00016 {
00017 ACE_TRACE ("ACE_FIFO_Recv_Msg::recv");
00018 #if defined (ACE_HAS_STREAM_PIPES)
00019 int i = 0;
00020 if (ACE_OS::getmsg (this->get_handle (),
00021 (strbuf *) 0,
00022 (strbuf *) &recv_msg,
00023 &i) == -1)
00024 return -1;
00025 else
00026 return recv_msg.len;
00027 #else
00028 if (ACE_OS::read (this->get_handle (),
00029 (char *) &recv_msg.len,
00030 sizeof recv_msg.len) != sizeof recv_msg.len)
00031 return -1;
00032 else
00033 {
00034 size_t remaining = static_cast<size_t> (recv_msg.len);
00035 size_t requested = static_cast<size_t> (recv_msg.maxlen);
00036 ssize_t recv_len = ACE_OS::read (this->get_handle (),
00037 (char *) recv_msg.buf,
00038 ACE_MIN (remaining, requested));
00039 if (recv_len == -1)
00040 return -1;
00041
00042 recv_msg.len = static_cast<int> (recv_len);
00043
00044
00045
00046
00047
00048
00049
00050 size_t total_msg_size = remaining;
00051 remaining -= recv_len;
00052 while (remaining > 0)
00053 {
00054 const size_t throw_away = 1024;
00055 char dev_null[throw_away];
00056 recv_len = ACE_OS::read (this->get_handle (),
00057 dev_null,
00058 ACE_MIN (remaining, throw_away));
00059 if (recv_len == -1)
00060 break;
00061 remaining -= recv_len;
00062 }
00063 return total_msg_size;
00064 }
00065 #endif
00066 }
00067
00068 ACE_INLINE ssize_t
00069 ACE_FIFO_Recv_Msg::recv (void *buf, size_t max_len)
00070 {
00071 ACE_TRACE ("ACE_FIFO_Recv_Msg::recv");
00072 ACE_Str_Buf recv_msg ((char *) buf, 0, static_cast<int> (max_len));
00073
00074 return this->recv (recv_msg);
00075 }
00076
00077 #if defined (ACE_HAS_STREAM_PIPES)
00078 ACE_INLINE ssize_t
00079 ACE_FIFO_Recv_Msg::recv (ACE_Str_Buf *data,
00080 ACE_Str_Buf *cntl,
00081 int *flags)
00082 {
00083 ACE_TRACE ("ACE_FIFO_Recv_Msg::recv");
00084 if (ACE_OS::getmsg (this->get_handle (),
00085 (strbuf *) cntl,
00086 (strbuf *) data,
00087 flags) == -1)
00088 return -1;
00089 else
00090 return (cntl == 0 ? 0 : cntl->len) + (data == 0 ? 0 : data->len);
00091 }
00092
00093 ACE_INLINE ssize_t
00094 ACE_FIFO_Recv_Msg::recv (int *band,
00095 ACE_Str_Buf *data,
00096 ACE_Str_Buf *cntl,
00097 int *flags)
00098 {
00099 ACE_TRACE ("ACE_FIFO_Recv_Msg::recv");
00100 if (ACE_OS::getpmsg (this->get_handle (),
00101 (strbuf *) cntl,
00102 (strbuf *) data,
00103 band,
00104 flags) == -1)
00105 return -1;
00106 else
00107 return (cntl == 0 ? 0 : cntl->len) + (data == 0 ? 0 : data->len);
00108 }
00109 #endif
00110
00111 ACE_END_VERSIONED_NAMESPACE_DECL