Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

FIFO_Recv_Msg.i

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 // $Id: FIFO_Recv_Msg.i,v 1.1.1.3 2003/02/21 18:36:32 chad Exp $
00003 
00004 // FIFO_Recv_Msg.i
00005 
00006 ASYS_INLINE ssize_t
00007 ACE_FIFO_Recv_Msg::recv (ACE_Str_Buf &recv_msg)
00008 {
00009   ACE_TRACE ("ACE_FIFO_Recv_Msg::recv");
00010 #if defined (ACE_HAS_STREAM_PIPES)
00011   int i = 0;
00012   if (ACE_OS::getmsg (this->get_handle (),
00013                       (strbuf *) 0,
00014                       (strbuf *) &recv_msg,
00015                       &i) == -1)
00016     return -1;
00017   else 
00018     return recv_msg.len;
00019 #else /* Do the ol' 2-read trick... */
00020   if (ACE_OS::read (this->get_handle (), 
00021                     (char *) &recv_msg.len, 
00022                     sizeof recv_msg.len) != sizeof recv_msg.len)
00023     return -1;
00024   else
00025     {
00026       size_t remaining = ACE_static_cast (size_t, recv_msg.len);
00027       size_t requested = ACE_static_cast (size_t, recv_msg.maxlen);
00028       ssize_t recv_len = ACE_OS::read (this->get_handle (), 
00029                                        (char *) recv_msg.buf, 
00030                                        ACE_MIN (remaining, requested));
00031       if (recv_len == -1)
00032         return -1;
00033       // Tell caller what's really in the buffer.
00034       recv_msg.len = ACE_static_cast (int, recv_len);
00035 
00036       // If there are more bytes remaining in the message, read them and
00037       // throw them away. Leaving them in the FIFO would make it difficult
00038       // to find the start of the next message in the fifo.
00039       // Since the ACE_HAS_STREAM_PIPES version of this method doesn't
00040       // return getmsg()'s indication of "data remaining", don't worry about
00041       // saving the indication here either to read the remainder later.
00042       size_t total_msg_size = remaining;
00043       remaining -= recv_len;
00044       while (remaining > 0)
00045         {
00046           const size_t throw_away = 1024;
00047           char dev_null[throw_away];
00048           recv_len = ACE_OS::read (this->get_handle (),
00049                                    dev_null,
00050                                    ACE_MIN (remaining, throw_away));
00051           if (recv_len == -1)
00052             break;
00053           remaining -= recv_len;
00054         }
00055       return total_msg_size;
00056     }
00057 #endif /* ACE_HAS_STREAM_PIPES */
00058 }
00059 
00060 ASYS_INLINE ssize_t
00061 ACE_FIFO_Recv_Msg::recv (void *buf, size_t max_len)
00062 {
00063   ACE_TRACE ("ACE_FIFO_Recv_Msg::recv");
00064   ACE_Str_Buf recv_msg ((char *) buf, 0, ACE_static_cast (int, max_len));
00065 
00066   return this->recv (recv_msg);
00067 }
00068 
00069 #if defined (ACE_HAS_STREAM_PIPES)
00070 ASYS_INLINE ssize_t
00071 ACE_FIFO_Recv_Msg::recv (ACE_Str_Buf *data,
00072                          ACE_Str_Buf *cntl,
00073                          int *flags)
00074 {
00075   ACE_TRACE ("ACE_FIFO_Recv_Msg::recv");
00076   if (ACE_OS::getmsg (this->get_handle (), 
00077                       (strbuf *) cntl,
00078                       (strbuf *) data,
00079                       flags) == -1)
00080     return -1;
00081   else
00082     return (cntl == 0 ? 0 : cntl->len) + (data == 0 ? 0 : data->len);
00083 }
00084 
00085 ASYS_INLINE ssize_t
00086 ACE_FIFO_Recv_Msg::recv (int *band,
00087                          ACE_Str_Buf *data,
00088                          ACE_Str_Buf *cntl,
00089                          int *flags)
00090 {
00091   ACE_TRACE ("ACE_FIFO_Recv_Msg::recv");
00092   if (ACE_OS::getpmsg (this->get_handle (), 
00093                        (strbuf *) cntl,
00094                        (strbuf *) data,
00095                        band,
00096                        flags) == -1)
00097     return -1;
00098   else
00099     return (cntl == 0 ? 0 : cntl->len) + (data == 0 ? 0 : data->len);
00100 }
00101 #endif /* ACE_HAS_STREAM_PIPES */

Generated on Mon Jun 16 11:19:39 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002