[6916] Fixed typos in spell checking code.
[getmangos.git] / dep / ACE_wrappers / ace / FILE_IO.cpp
blobd6bf084dfae87d33136f2a1faa3dcbd4d1d068f1
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)
20 void
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));
27 this->addr_.dump ();
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!
44 ssize_t
45 ACE_FILE_IO::send (size_t n, ...) const
47 ACE_TRACE ("ACE_FILE_IO::send");
48 va_list argp;
49 int total_tuples = ACE_Utils::truncate_cast<int> (n / 2);
50 iovec *iovp = 0;
51 #if defined (ACE_HAS_ALLOCA)
52 iovp = (iovec *) alloca (total_tuples * sizeof (iovec));
53 #else
54 ACE_NEW_RETURN (iovp,
55 iovec[total_tuples],
56 -1);
57 #endif /* !defined (ACE_HAS_ALLOCA) */
59 va_start (argp, n);
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 (),
68 iovp,
69 total_tuples);
70 #if !defined (ACE_HAS_ALLOCA)
71 delete [] iovp;
72 #endif /* !defined (ACE_HAS_ALLOCA) */
73 va_end (argp);
74 return result;
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
81 // of tuple pairs!
83 ssize_t
84 ACE_FILE_IO::recv (size_t n, ...) const
86 ACE_TRACE ("ACE_FILE_IO::recv");
87 va_list argp;
88 int total_tuples = ACE_Utils::truncate_cast<int> (n / 2);
89 iovec *iovp = 0;
90 #if defined (ACE_HAS_ALLOCA)
91 iovp = (iovec *) alloca (total_tuples * sizeof (iovec));
92 #else
93 ACE_NEW_RETURN (iovp,
94 iovec[total_tuples],
95 -1);
96 #endif /* !defined (ACE_HAS_ALLOCA) */
98 va_start (argp, n);
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 (),
107 iovp,
108 total_tuples);
109 #if !defined (ACE_HAS_ALLOCA)
110 delete [] iovp;
111 #endif /* !defined (ACE_HAS_ALLOCA) */
112 va_end (argp);
113 return result;
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.
121 ssize_t
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 ()));
130 if (length > 0)
132 ACE_NEW_RETURN (io_vec->iov_base,
133 char[length],
134 -1);
135 io_vec->iov_len = this->recv_n (io_vec->iov_base,
136 length);
137 return io_vec->iov_len;
139 else
141 return ACE_Utils::truncate_cast<ssize_t> (length);
145 ACE_END_VERSIONED_NAMESPACE_DECL