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