FILE_IO.cpp

Go to the documentation of this file.
00001 // FILE_IO.cpp,v 4.29 2006/06/09 14:02:33 jwillemsen Exp
00002 
00003 #include "ace/FILE_IO.h"
00004 
00005 #include "ace/Log_Msg.h"
00006 #include "ace/OS_NS_sys_stat.h"
00007 #include "ace/OS_Memory.h"
00008 #include "ace/Truncate.h"
00009 
00010 #if !defined (__ACE_INLINE__)
00011 #include "ace/FILE_IO.inl"
00012 #endif /* __ACE_INLINE__ */
00013 
00014 ACE_RCSID(ace, FILE_IO, "FILE_IO.cpp,v 4.29 2006/06/09 14:02:33 jwillemsen Exp")
00015 
00016 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00017 
00018 ACE_ALLOC_HOOK_DEFINE(ACE_FILE_IO)
00019 
00020 void
00021 ACE_FILE_IO::dump (void) const
00022 {
00023 #if defined (ACE_HAS_DUMP)
00024   ACE_TRACE ("ACE_FILE_IO::dump");
00025 
00026   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00027   this->addr_.dump ();
00028   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00029 #endif /* ACE_HAS_DUMP */
00030 }
00031 
00032 // Simple-minded do nothing constructor.
00033 
00034 ACE_FILE_IO::ACE_FILE_IO (void)
00035 {
00036   ACE_TRACE ("ACE_FILE_IO::ACE_FILE_IO");
00037 }
00038 
00039 // Send N char *ptrs and int lengths.  Note that the char *'s precede
00040 // the ints (basically, an varargs version of writev).  The count N is
00041 // the *total* number of trailing arguments, *not* a couple of the
00042 // number of tuple pairs!
00043 
00044 ssize_t
00045 ACE_FILE_IO::send (size_t n, ...) const
00046 {
00047   ACE_TRACE ("ACE_FILE_IO::send");
00048   va_list argp;
00049   int total_tuples = ACE_Utils::Truncate (n / 2);
00050   iovec *iovp = 0;
00051 #if defined (ACE_HAS_ALLOCA)
00052   iovp = (iovec *) alloca (total_tuples * sizeof (iovec));
00053 #else
00054   ACE_NEW_RETURN (iovp,
00055                   iovec[total_tuples],
00056                   -1);
00057 #endif /* !defined (ACE_HAS_ALLOCA) */
00058 
00059   va_start (argp, n);
00060 
00061   for (int i = 0; i < total_tuples; i++)
00062     {
00063       iovp[i].iov_base = va_arg (argp, char *);
00064       iovp[i].iov_len  = va_arg (argp, int);
00065     }
00066 
00067   ssize_t result = ACE_OS::writev (this->get_handle (),
00068                                    iovp,
00069                                    total_tuples);
00070 #if !defined (ACE_HAS_ALLOCA)
00071   delete [] iovp;
00072 #endif /* !defined (ACE_HAS_ALLOCA) */
00073   va_end (argp);
00074   return result;
00075 }
00076 
00077 // This is basically an interface to ACE_OS::readv, that doesn't use
00078 // the struct iovec explicitly.  The ... can be passed as an arbitrary
00079 // number of (char *ptr, int len) tuples.  However, the count N is the
00080 // *total* number of trailing arguments, *not* a couple of the number
00081 // of tuple pairs!
00082 
00083 ssize_t
00084 ACE_FILE_IO::recv (size_t n, ...) const
00085 {
00086   ACE_TRACE ("ACE_FILE_IO::recv");
00087   va_list argp;
00088   int total_tuples = ACE_Utils::Truncate (n / 2);
00089   iovec *iovp = 0;
00090 #if defined (ACE_HAS_ALLOCA)
00091   iovp = (iovec *) alloca (total_tuples * sizeof (iovec));
00092 #else
00093   ACE_NEW_RETURN (iovp,
00094                   iovec[total_tuples],
00095                   -1);
00096 #endif /* !defined (ACE_HAS_ALLOCA) */
00097 
00098   va_start (argp, n);
00099 
00100   for (int i = 0; i < total_tuples; i++)
00101     {
00102       iovp[i].iov_base = va_arg (argp, char *);
00103       iovp[i].iov_len  = va_arg (argp, int);
00104     }
00105 
00106   ssize_t const result = ACE_OS::readv (this->get_handle (),
00107                                         iovp,
00108                                         total_tuples);
00109 #if !defined (ACE_HAS_ALLOCA)
00110   delete [] iovp;
00111 #endif /* !defined (ACE_HAS_ALLOCA) */
00112   va_end (argp);
00113   return result;
00114 }
00115 
00116 // Allows a client to read from a file without having to provide a
00117 // buffer to read.  This method determines how much data is in the
00118 // file, allocates a buffer of this size, reads in the data, and
00119 // returns the number of bytes read.
00120 
00121 ssize_t
00122 ACE_FILE_IO::recvv (iovec *io_vec)
00123 {
00124   ACE_TRACE ("ACE_FILE_IO::recvv");
00125 
00126   io_vec->iov_base = 0;
00127   size_t const length = static_cast <size_t> (ACE_OS::filesize (this->get_handle ()));
00128 
00129   if (length > 0)
00130     {
00131       ACE_NEW_RETURN (io_vec->iov_base,
00132                       char[length],
00133                       -1);
00134       io_vec->iov_len = this->recv_n (io_vec->iov_base,
00135                                       length);
00136       return io_vec->iov_len;
00137     }
00138   else
00139     return length;
00140 }
00141 
00142 ACE_END_VERSIONED_NAMESPACE_DECL

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