FIFO_Recv_Msg.inl

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // FIFO_Recv_Msg.inl,v 4.2 2005/10/28 16:14:52 ossama Exp
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 /* Do the ol' 2-read trick... */
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       // Tell caller what's really in the buffer.
00042       recv_msg.len = static_cast<int> (recv_len);
00043 
00044       // If there are more bytes remaining in the message, read them and
00045       // throw them away. Leaving them in the FIFO would make it difficult
00046       // to find the start of the next message in the fifo.
00047       // Since the ACE_HAS_STREAM_PIPES version of this method doesn't
00048       // return getmsg()'s indication of "data remaining", don't worry about
00049       // saving the indication here either to read the remainder later.
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 /* ACE_HAS_STREAM_PIPES */
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 /* ACE_HAS_STREAM_PIPES */
00110 
00111 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 09:41:50 2006 for ACE by doxygen 1.3.6