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

FILE_IO.cpp

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

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