1 #include "ace/OS_NS_sys_uio.h"
3 #if !defined (ACE_HAS_INLINED_OSCALLS)
4 # include "ace/OS_NS_sys_uio.inl"
5 #endif /* ACE_HAS_INLINED_OSCALLS */
7 #include "ace/OS_Memory.h"
8 #include "ace/OS_NS_string.h"
9 #include "ace/OS_NS_unistd.h"
11 #ifdef ACE_HAS_ALLOC_HOOKS
12 # include "ace/Global_Macros.h"
13 # include "ace/Malloc_Base.h"
16 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
18 #if defined (ACE_LACKS_READV)
20 // "Fake" readv for operating systems without it. Note that this is
24 ACE_OS::readv_emulation (ACE_HANDLE handle
,
28 ACE_OS_TRACE ("ACE_OS::readv_emulation");
30 // In case there's a single element, skip the memcpy.
32 return ACE_OS::read (handle
, iov
[0].iov_base
, iov
[0].iov_len
);
37 for (i
= 0; i
< n
; ++i
)
38 if (static_cast<int> (iov
[i
].iov_len
) < 0)
41 length
+= iov
[i
].iov_len
;
44 # ifdef ACE_HAS_ALLOC_HOOKS
45 ACE_ALLOCATOR_RETURN (buf
,
46 (char *) ACE_Allocator::instance ()->malloc (length
),
52 # endif /* ACE_HAS_ALLOC_HOOKS */
54 length
= ACE_OS::read (handle
, buf
, length
);
59 ssize_t copyn
= length
;
65 ACE_OS::memcpy (iov
[i
].iov_base
, ptr
,
66 // iov_len is int on some platforms, size_t on others
67 copyn
> (int) iov
[i
].iov_len
68 ? (size_t) iov
[i
].iov_len
70 ptr
+= iov
[i
].iov_len
;
71 copyn
-= iov
[i
].iov_len
;
75 # ifdef ACE_HAS_ALLOC_HOOKS
76 ACE_Allocator::instance ()->free (buf
);
79 # endif /* ACE_HAS_ALLOC_HOOKS */
82 #endif /* ACE_LACKS_READV */
84 #if defined (ACE_LACKS_WRITEV)
86 // "Fake" writev for operating systems without it. Note that this is
90 ACE_OS::writev_emulation (ACE_HANDLE handle
, const iovec
*iov
, int n
)
92 ACE_OS_TRACE ("ACE_OS::writev_emulation");
94 // 'handle' may be a datagram socket (or similar) so this operation
95 // must not be divided into multiple smaller writes.
98 return ACE_OS::write (handle
, iov
[0].iov_base
, iov
[0].iov_len
);
101 for (int i
= 0; i
< n
; ++i
)
102 length
+= iov
[i
].iov_len
;
105 # ifdef ACE_HAS_ALLOC_HOOKS
106 ACE_ALLOCATOR_RETURN (buf
,
107 (char *) ACE_Allocator::instance ()->malloc (length
),
110 ACE_NEW_RETURN (buf
, char[length
], -1);
111 # endif /* ACE_HAS_ALLOC_HOOKS */
114 for (int i
= 0; i
< n
; iter
+= iov
[i
++].iov_len
)
115 ACE_OS::memcpy (iter
, iov
[i
].iov_base
, iov
[i
].iov_len
);
117 const ssize_t result
= ACE_OS::write (handle
, buf
, length
);
119 # ifdef ACE_HAS_ALLOC_HOOKS
120 ACE_Allocator::instance ()->free (buf
);
123 # endif /* ACE_HAS_ALLOC_HOOKS */
127 # endif /* ACE_LACKS_WRITEV */
129 ACE_END_VERSIONED_NAMESPACE_DECL