1 #include "ace/SOCK_IO.h"
3 #include "ace/OS_NS_sys_socket.h"
4 #include "ace/OS_Memory.h"
5 #include "ace/Truncate.h"
7 #if defined (ACE_HAS_ALLOC_HOOKS)
8 # include "ace/Malloc_Base.h"
9 #endif /* ACE_HAS_ALLOC_HOOKS */
11 #if !defined (__ACE_INLINE__)
12 #include "ace/SOCK_IO.inl"
13 #endif /* __ACE_INLINE__ */
15 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
17 ACE_ALLOC_HOOK_DEFINE(ACE_SOCK_IO
)
20 ACE_SOCK_IO::dump () const
22 #if defined (ACE_HAS_DUMP)
23 ACE_TRACE ("ACE_SOCK_IO::dump");
24 #endif /* ACE_HAS_DUMP */
27 // Allows a client to read from a socket without having to provide
28 // a buffer to read. This method determines how much data is in the
29 // socket, allocates a buffer of this size, reads in the data, and
30 // returns the number of bytes read.
33 ACE_SOCK_IO::recvv (iovec
*io_vec
,
34 const ACE_Time_Value
*timeout
) const
36 ACE_TRACE ("ACE_SOCK_IO::recvv");
37 #if defined (FIONREAD)
39 if( ACE::handle_read_ready (this->get_handle (), timeout
) != 1 )
46 if (ACE_OS::ioctl (this->get_handle (),
52 #if defined (ACE_HAS_ALLOC_HOOKS)
53 ACE_ALLOCATOR_RETURN (io_vec
->iov_base
,
54 static_cast<char*>(ACE_Allocator::instance()->malloc(sizeof(char) * inlen
)),
57 ACE_NEW_RETURN (io_vec
->iov_base
,
60 #endif /* ACE_HAS_ALLOC_HOOKS */
62 // It's ok to blindly cast this value since 'inlen' is an int and, thus,
63 // we can't get more than that back. Besides, if the recv() fails, we
64 // don't want that value cast to unsigned and returned.
65 ssize_t recv_len
= this->recv (io_vec
->iov_base
, inlen
);
67 // u_long is the Windows type; size_t is everyone else's. A u_long
68 // should go into a size_t anywhere without an issue.
69 io_vec
->iov_len
= static_cast<u_long
> (recv_len
);
75 ACE_UNUSED_ARG (io_vec
);
76 ACE_UNUSED_ARG (timeout
);
77 ACE_NOTSUP_RETURN (-1);
81 // Send N char *ptrs and int lengths. Note that the char *'s precede
82 // the ints (basically, an varargs version of writev). The count N is
83 // the *total* number of trailing arguments, *not* a couple of the
84 // number of tuple pairs!
85 #ifndef ACE_LACKS_VA_FUNCTIONS
87 ACE_SOCK_IO::send (size_t n
, ...) const
89 ACE_TRACE ("ACE_SOCK_IO::send");
92 int const total_tuples
= ACE_Utils::truncate_cast
<int> (n
/ 2);
94 #if defined (ACE_HAS_ALLOCA)
95 iovp
= (iovec
*) alloca (total_tuples
* sizeof (iovec
));
97 # ifdef ACE_HAS_ALLOC_HOOKS
98 ACE_ALLOCATOR_RETURN (iovp
, (iovec
*)
99 ACE_Allocator::instance ()->malloc (total_tuples
*
103 ACE_NEW_RETURN (iovp
,
106 # endif /* ACE_HAS_ALLOC_HOOKS */
107 #endif /* !defined (ACE_HAS_ALLOCA) */
111 for (int i
= 0; i
< total_tuples
; i
++)
113 iovp
[i
].iov_base
= va_arg (argp
, char *);
114 iovp
[i
].iov_len
= va_arg (argp
, int);
117 ssize_t
const result
= ACE_OS::sendv (this->get_handle (),
120 #if !defined (ACE_HAS_ALLOCA)
121 # ifdef ACE_HAS_ALLOC_HOOKS
122 ACE_Allocator::instance ()->free (iovp
);
125 # endif /* ACE_HAS_ALLOC_HOOKS */
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 const total_tuples
= ACE_Utils::truncate_cast
<int> (n
/ 2);
145 #if defined (ACE_HAS_ALLOCA)
146 iovp
= (iovec
*) alloca (total_tuples
* sizeof (iovec
));
148 # ifdef ACE_HAS_ALLOC_HOOKS
149 ACE_ALLOCATOR_RETURN (iovp
, (iovec
*)
150 ACE_Allocator::instance ()->malloc (total_tuples
*
154 ACE_NEW_RETURN (iovp
,
157 # endif /* ACE_HAS_ALLOC_HOOKS */
158 #endif /* !defined (ACE_HAS_ALLOCA) */
162 for (int i
= 0; i
< total_tuples
; i
++)
164 iovp
[i
].iov_base
= va_arg (argp
, char *);
165 iovp
[i
].iov_len
= va_arg (argp
, int);
168 ssize_t
const result
= ACE_OS::recvv (this->get_handle (),
171 #if !defined (ACE_HAS_ALLOCA)
172 # ifdef ACE_HAS_ALLOC_HOOKS
173 ACE_Allocator::instance ()->free (iovp
);
176 # endif /* ACE_HAS_ALLOC_HOOKS */
177 #endif /* !defined (ACE_HAS_ALLOCA) */
181 #endif // ACE_LACKS_VA_FUNCTIONS
183 ACE_END_VERSIONED_NAMESPACE_DECL