1 // $Id: FILE_IO.cpp 82559 2008-08-07 20:23:07Z parsons $
3 #include "ace/FILE_IO.h"
5 #include "ace/Log_Msg.h"
6 #include "ace/OS_NS_sys_stat.h"
7 #include "ace/OS_Memory.h"
8 #include "ace/Truncate.h"
10 #if !defined (__ACE_INLINE__)
11 #include "ace/FILE_IO.inl"
12 #endif /* __ACE_INLINE__ */
14 ACE_RCSID(ace
, FILE_IO
, "$Id: FILE_IO.cpp 82559 2008-08-07 20:23:07Z parsons $")
16 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
18 ACE_ALLOC_HOOK_DEFINE(ACE_FILE_IO
)
21 ACE_FILE_IO::dump (void) const
23 #if defined (ACE_HAS_DUMP)
24 ACE_TRACE ("ACE_FILE_IO::dump");
26 ACE_DEBUG ((LM_DEBUG
, ACE_BEGIN_DUMP
, this));
28 ACE_DEBUG ((LM_DEBUG
, ACE_END_DUMP
));
29 #endif /* ACE_HAS_DUMP */
32 // Simple-minded do nothing constructor.
34 ACE_FILE_IO::ACE_FILE_IO (void)
36 ACE_TRACE ("ACE_FILE_IO::ACE_FILE_IO");
39 // Send N char *ptrs and int lengths. Note that the char *'s precede
40 // the ints (basically, an varargs version of writev). The count N is
41 // the *total* number of trailing arguments, *not* a couple of the
42 // number of tuple pairs!
45 ACE_FILE_IO::send (size_t n
, ...) const
47 ACE_TRACE ("ACE_FILE_IO::send");
49 int total_tuples
= ACE_Utils::truncate_cast
<int> (n
/ 2);
51 #if defined (ACE_HAS_ALLOCA)
52 iovp
= (iovec
*) alloca (total_tuples
* sizeof (iovec
));
57 #endif /* !defined (ACE_HAS_ALLOCA) */
61 for (int i
= 0; i
< total_tuples
; i
++)
63 iovp
[i
].iov_base
= va_arg (argp
, char *);
64 iovp
[i
].iov_len
= va_arg (argp
, int);
67 ssize_t result
= ACE_OS::writev (this->get_handle (),
70 #if !defined (ACE_HAS_ALLOCA)
72 #endif /* !defined (ACE_HAS_ALLOCA) */
77 // This is basically an interface to ACE_OS::readv, that doesn't use
78 // the struct iovec explicitly. The ... can be passed as an arbitrary
79 // number of (char *ptr, int len) tuples. However, the count N is the
80 // *total* number of trailing arguments, *not* a couple of the number
84 ACE_FILE_IO::recv (size_t n
, ...) const
86 ACE_TRACE ("ACE_FILE_IO::recv");
88 int total_tuples
= ACE_Utils::truncate_cast
<int> (n
/ 2);
90 #if defined (ACE_HAS_ALLOCA)
91 iovp
= (iovec
*) alloca (total_tuples
* sizeof (iovec
));
96 #endif /* !defined (ACE_HAS_ALLOCA) */
100 for (int i
= 0; i
< total_tuples
; i
++)
102 iovp
[i
].iov_base
= va_arg (argp
, char *);
103 iovp
[i
].iov_len
= va_arg (argp
, int);
106 ssize_t
const result
= ACE_OS::readv (this->get_handle (),
109 #if !defined (ACE_HAS_ALLOCA)
111 #endif /* !defined (ACE_HAS_ALLOCA) */
116 // Allows a client to read from a file without having to provide a
117 // buffer to read. This method determines how much data is in the
118 // file, allocates a buffer of this size, reads in the data, and
119 // returns the number of bytes read.
122 ACE_FILE_IO::recvv (iovec
*io_vec
)
124 ACE_TRACE ("ACE_FILE_IO::recvv");
126 io_vec
->iov_base
= 0;
127 size_t const length
=
128 static_cast <size_t> (ACE_OS::filesize (this->get_handle ()));
132 ACE_NEW_RETURN (io_vec
->iov_base
,
135 io_vec
->iov_len
= this->recv_n (io_vec
->iov_base
,
137 return io_vec
->iov_len
;
141 return ACE_Utils::truncate_cast
<ssize_t
> (length
);
145 ACE_END_VERSIONED_NAMESPACE_DECL