SPIPE_Stream.cpp

Go to the documentation of this file.
00001 // SPIPE_Stream.cpp,v 4.15 2005/10/28 16:14:55 ossama Exp
00002 
00003 #include "ace/SPIPE_Stream.h"
00004 #include "ace/OS_Memory.h"
00005 
00006 #if !defined (__ACE_INLINE__)
00007 #include "ace/SPIPE_Stream.inl"
00008 #endif /* __ACE_INLINE__ */
00009 
00010 ACE_RCSID(ace, SPIPE_Stream, "SPIPE_Stream.cpp,v 4.15 2005/10/28 16:14:55 ossama Exp")
00011 
00012 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00013 
00014 ACE_ALLOC_HOOK_DEFINE(ACE_SPIPE_Stream)
00015 
00016 void
00017 ACE_SPIPE_Stream::dump (void) const
00018 {
00019 #if defined (ACE_HAS_DUMP)
00020   ACE_TRACE ("ACE_SPIPE_Stream::dump");
00021 #endif /* ACE_HAS_DUMP */
00022 }
00023 
00024 // Simple-minded do nothing constructor.
00025 
00026 ACE_SPIPE_Stream::ACE_SPIPE_Stream (void)
00027 {
00028   // ACE_TRACE ("ACE_SPIPE_Stream::ACE_SPIPE_Stream");
00029 }
00030 
00031 // Send N char *ptrs and int lengths.  Note that the char *'s precede
00032 // the ints (basically, an varargs version of writev).  The count N is
00033 // the *total* number of trailing arguments, *not* a couple of the
00034 // number of tuple pairs!
00035 
00036 ssize_t
00037 ACE_SPIPE_Stream::send (size_t n, ...) const
00038 {
00039   // ACE_TRACE ("ACE_SPIPE_Stream::send");
00040   va_list argp;
00041   int total_tuples = static_cast<int> (n / 2);
00042   iovec *iovp;
00043 #if defined (ACE_HAS_ALLOCA)
00044   iovp = (iovec *) alloca (total_tuples * sizeof (iovec));
00045 #else
00046   ACE_NEW_RETURN (iovp,
00047                   iovec[total_tuples],
00048                   -1);
00049 #endif /* !defined (ACE_HAS_ALLOCA) */
00050 
00051   va_start (argp, n);
00052 
00053   for (int i = 0; i < total_tuples; i++)
00054     {
00055       iovp[i].iov_base = va_arg (argp, char *);
00056       iovp[i].iov_len  = va_arg (argp, int);
00057     }
00058 
00059   ssize_t result = ACE_OS::writev (this->get_handle (), iovp, total_tuples);
00060 #if !defined (ACE_HAS_ALLOCA)
00061   delete [] iovp;
00062 #endif /* !defined (ACE_HAS_ALLOCA) */
00063   va_end (argp);
00064   return result;
00065 }
00066 
00067 // This is basically an interface to ACE_OS::readv, that doesn't use
00068 // the struct iovec explicitly.  The ... can be passed as an arbitrary
00069 // number of (char *ptr, int len) tuples.  However, the count N is the
00070 // *total* number of trailing arguments, *not* a couple of the number
00071 // of tuple pairs!
00072 
00073 ssize_t
00074 ACE_SPIPE_Stream::recv (size_t n, ...) const
00075 {
00076   ACE_TRACE ("ACE_SPIPE_Stream::recv");
00077   va_list argp;
00078   int total_tuples = static_cast<int> (n / 2);
00079   iovec *iovp;
00080 #if defined (ACE_HAS_ALLOCA)
00081   iovp = (iovec *) alloca (total_tuples * sizeof (iovec));
00082 #else
00083   ACE_NEW_RETURN (iovp,
00084                   iovec[total_tuples],
00085                   -1);
00086 #endif /* !defined (ACE_HAS_ALLOCA) */
00087 
00088   va_start (argp, n);
00089 
00090   for (int i = 0; i < total_tuples; i++)
00091     {
00092       iovp[i].iov_base = va_arg (argp, char *);
00093       iovp[i].iov_len  = va_arg (argp, int);
00094     }
00095 
00096   ssize_t result = ACE_OS::readv (this->get_handle (), iovp, total_tuples);
00097 #if !defined (ACE_HAS_ALLOCA)
00098   delete [] iovp;
00099 #endif /* !defined (ACE_HAS_ALLOCA) */
00100   va_end (argp);
00101   return result;
00102 }
00103 
00104 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 09:42:04 2006 for ACE by doxygen 1.3.6