2
// SOCK_IO.cpp,v 4.25 2003/11/01 11:15:17 dhinton Exp
4
#include "ace/SOCK_IO.h"
6
#if defined (ACE_LACKS_INLINE_FUNCTIONS)
7
#include "ace/SOCK_IO.i"
8
#endif /* ACE_LACKS_INLINE_FUNCTIONS */
10
#include "ace/Handle_Set.h"
11
#include "ace/OS_NS_sys_select.h"
13
ACE_RCSID(ace, SOCK_IO, "SOCK_IO.cpp,v 4.25 2003/11/01 11:15:17 dhinton Exp")
15
ACE_ALLOC_HOOK_DEFINE(ACE_SOCK_IO)
18
ACE_SOCK_IO::dump (void) const
20
#if defined (ACE_HAS_DUMP)
21
ACE_TRACE ("ACE_SOCK_IO::dump");
22
#endif /* ACE_HAS_DUMP */
25
// Allows a client to read from a socket without having to provide
26
// a buffer to read. This method determines how much data is in the
27
// socket, allocates a buffer of this size, reads in the data, and
28
// returns the number of bytes read.
31
ACE_SOCK_IO::recvv (iovec *io_vec,
32
const ACE_Time_Value *timeout) const
34
ACE_TRACE ("ACE_SOCK_IO::recvv");
35
#if defined (FIONREAD)
36
ACE_Handle_Set handle_set;
38
handle_set.set_bit (this->get_handle ());
42
// Check the status of the current socket.
44
# if defined (ACE_WIN64)
45
// This arg is ignored on Windows and causes pointer truncation
46
// warnings on 64-bit compiles.
49
select_width = int (this->get_handle ()) + 1;
50
# endif /* ACE_WIN64 */
51
switch (ACE_OS::select (select_width,
64
// Goes fine, fallthrough to get data
70
if (ACE_OS::ioctl (this->get_handle (),
72
(u_long *) &inlen) == -1)
76
ACE_NEW_RETURN (io_vec->iov_base,
79
io_vec->iov_len = this->recv (io_vec->iov_base,
81
return io_vec->iov_len;
86
ACE_UNUSED_ARG (io_vec);
87
ACE_UNUSED_ARG (timeout);
88
ACE_NOTSUP_RETURN (-1);
92
// Send N char *ptrs and int lengths. Note that the char *'s precede
93
// the ints (basically, an varargs version of writev). The count N is
94
// the *total* number of trailing arguments, *not* a couple of the
95
// number of tuple pairs!
98
ACE_SOCK_IO::send (size_t n, ...) const
100
ACE_TRACE ("ACE_SOCK_IO::send");
103
int total_tuples = ACE_static_cast (int, n) / 2;
105
#if defined (ACE_HAS_ALLOCA)
106
iovp = (iovec *) alloca (total_tuples * sizeof (iovec));
108
ACE_NEW_RETURN (iovp,
111
#endif /* !defined (ACE_HAS_ALLOCA) */
115
for (int i = 0; i < total_tuples; i++)
117
iovp[i].iov_base = va_arg (argp, char *);
118
iovp[i].iov_len = va_arg (argp, int);
121
ssize_t result = ACE_OS::sendv (this->get_handle (),
124
#if !defined (ACE_HAS_ALLOCA)
126
#endif /* !defined (ACE_HAS_ALLOCA) */
131
// This is basically an interface to ACE_OS::readv, that doesn't use
132
// the struct iovec_Base explicitly. The ... can be passed as an arbitrary
133
// number of (char *ptr, int len) tuples. However, the count N is the
134
// *total* number of trailing arguments, *not* a couple of the number
138
ACE_SOCK_IO::recv (size_t n, ...) const
140
ACE_TRACE ("ACE_SOCK_IO::recv");
143
int total_tuples = ACE_static_cast (int, (n / 2));
145
#if defined (ACE_HAS_ALLOCA)
146
iovp = (iovec *) alloca (total_tuples * sizeof (iovec));
148
ACE_NEW_RETURN (iovp,
151
#endif /* !defined (ACE_HAS_ALLOCA) */
155
for (int i = 0; i < total_tuples; i++)
157
iovp[i].iov_base = va_arg (argp, char *);
158
iovp[i].iov_len = va_arg (argp, int);
161
ssize_t result = ACE_OS::recvv (this->get_handle (),
164
#if !defined (ACE_HAS_ALLOCA)
166
#endif /* !defined (ACE_HAS_ALLOCA) */