DEV_IO.cpp

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

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