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

SPIPE_Stream.cpp

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

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