mirror of
https://github.com/mangosfour/server.git
synced 2025-12-13 04:37:00 +00:00
Some missing from merge.
Signed-off-by: Salja <salja2012@hotmail.de>
This commit is contained in:
parent
ec939a5bce
commit
f4be15a7af
1895 changed files with 160408 additions and 53601 deletions
|
|
@ -1,3 +1,5 @@
|
|||
// $Id: OS_NS_sys_uio.cpp 96519 2012-12-17 10:00:00Z johnnyw $
|
||||
|
||||
#include "ace/OS_NS_sys_uio.h"
|
||||
|
||||
#if !defined (ACE_HAS_INLINED_OSCALLS)
|
||||
|
|
@ -8,14 +10,9 @@
|
|||
#include "ace/OS_NS_string.h"
|
||||
#include "ace/OS_NS_unistd.h"
|
||||
|
||||
#ifdef ACE_HAS_ALLOC_HOOKS
|
||||
# include "ace/Global_Macros.h"
|
||||
# include "ace/Malloc_Base.h"
|
||||
#endif
|
||||
|
||||
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
|
||||
|
||||
#if defined (ACE_LACKS_READV)
|
||||
# if defined (ACE_LACKS_READV)
|
||||
|
||||
// "Fake" readv for operating systems without it. Note that this is
|
||||
// thread-safe.
|
||||
|
|
@ -41,15 +38,13 @@ ACE_OS::readv_emulation (ACE_HANDLE handle,
|
|||
length += iov[i].iov_len;
|
||||
|
||||
char *buf;
|
||||
# ifdef ACE_HAS_ALLOC_HOOKS
|
||||
ACE_ALLOCATOR_RETURN (buf,
|
||||
(char *) ACE_Allocator::instance ()->malloc (length),
|
||||
-1);
|
||||
# else
|
||||
# if defined (ACE_HAS_ALLOCA)
|
||||
buf = (char *) alloca (length);
|
||||
# else
|
||||
ACE_NEW_RETURN (buf,
|
||||
char[length],
|
||||
-1);
|
||||
# endif /* ACE_HAS_ALLOC_HOOKS */
|
||||
# endif /* !defined (ACE_HAS_ALLOCA) */
|
||||
|
||||
length = ACE_OS::read (handle, buf, length);
|
||||
|
||||
|
|
@ -72,16 +67,14 @@ ACE_OS::readv_emulation (ACE_HANDLE handle,
|
|||
}
|
||||
}
|
||||
|
||||
# ifdef ACE_HAS_ALLOC_HOOKS
|
||||
ACE_Allocator::instance ()->free (buf);
|
||||
# else
|
||||
# if !defined (ACE_HAS_ALLOCA)
|
||||
delete [] buf;
|
||||
# endif /* ACE_HAS_ALLOC_HOOKS */
|
||||
# endif /* !defined (ACE_HAS_ALLOCA) */
|
||||
return length;
|
||||
}
|
||||
#endif /* ACE_LACKS_READV */
|
||||
# endif /* ACE_LACKS_READV */
|
||||
|
||||
#if defined (ACE_LACKS_WRITEV)
|
||||
# if defined (ACE_LACKS_WRITEV)
|
||||
|
||||
// "Fake" writev for operating systems without it. Note that this is
|
||||
// thread-safe.
|
||||
|
|
@ -91,38 +84,44 @@ ACE_OS::writev_emulation (ACE_HANDLE handle, const iovec *iov, int n)
|
|||
{
|
||||
ACE_OS_TRACE ("ACE_OS::writev_emulation");
|
||||
|
||||
// 'handle' may be a datagram socket (or similar) so this operation
|
||||
// must not be divided into multiple smaller writes.
|
||||
// To avoid having to allocate a temporary buffer to which all of
|
||||
// the data will be copied and then written, this implementation
|
||||
// performs incremental writes.
|
||||
|
||||
if (n == 1)
|
||||
return ACE_OS::write (handle, iov[0].iov_base, iov[0].iov_len);
|
||||
ssize_t bytes_sent = 0;
|
||||
|
||||
ssize_t length = 0;
|
||||
for (int i = 0; i < n; ++i)
|
||||
length += iov[i].iov_len;
|
||||
{
|
||||
ssize_t const result =
|
||||
ACE_OS::write (handle, iov[i].iov_base, iov[i].iov_len);
|
||||
|
||||
char *buf;
|
||||
# ifdef ACE_HAS_ALLOC_HOOKS
|
||||
ACE_ALLOCATOR_RETURN (buf,
|
||||
(char *) ACE_Allocator::instance ()->malloc (length),
|
||||
-1);
|
||||
# else
|
||||
ACE_NEW_RETURN (buf, char[length], -1);
|
||||
# endif /* ACE_HAS_ALLOC_HOOKS */
|
||||
if (result == -1)
|
||||
{
|
||||
// There is a subtle difference in behaviour depending on
|
||||
// whether or not any data was sent. If no data was sent,
|
||||
// then always return -1. Otherwise return bytes_sent.
|
||||
// This gives the caller an opportunity to keep track of
|
||||
// bytes that have already been sent.
|
||||
if (bytes_sent > 0)
|
||||
break;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
bytes_sent += result;
|
||||
|
||||
char *iter = buf;
|
||||
for (int i = 0; i < n; iter += iov[i++].iov_len)
|
||||
ACE_OS::memcpy (iter, iov[i].iov_base, iov[i].iov_len);
|
||||
// Do not continue on to the next loop iteration if the
|
||||
// amount of data sent was less than the amount data given.
|
||||
// This avoids a subtle problem where "holes" in the data
|
||||
// stream would occur if partial sends of a given buffer in
|
||||
// the iovec array occured.
|
||||
if (static_cast<size_t> (result) < iov[i].iov_len)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const ssize_t result = ACE_OS::write (handle, buf, length);
|
||||
|
||||
# ifdef ACE_HAS_ALLOC_HOOKS
|
||||
ACE_Allocator::instance ()->free (buf);
|
||||
# else
|
||||
delete[] buf;
|
||||
# endif /* ACE_HAS_ALLOC_HOOKS */
|
||||
|
||||
return result;
|
||||
return bytes_sent;
|
||||
}
|
||||
# endif /* ACE_LACKS_WRITEV */
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue