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

DEV_IO.cpp

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

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