Add data() and size() member functions to buffers.
The buffer_cast function is now deprecated.
This commit is contained in:
parent
24c6d7e3c7
commit
70aecd80ca
@ -444,7 +444,7 @@ protected:
|
|||||||
// Send all data in the output buffer.
|
// Send all data in the output buffer.
|
||||||
asio::const_buffer buffer =
|
asio::const_buffer buffer =
|
||||||
asio::buffer(pbase(), pptr() - pbase());
|
asio::buffer(pbase(), pptr() - pbase());
|
||||||
while (asio::buffer_size(buffer) > 0)
|
while (buffer.size() > 0)
|
||||||
{
|
{
|
||||||
if (timer_state_ == timer_has_expired)
|
if (timer_state_ == timer_has_expired)
|
||||||
{
|
{
|
||||||
|
@ -151,7 +151,7 @@ public:
|
|||||||
* while (i != bufs.end())
|
* while (i != bufs.end())
|
||||||
* {
|
* {
|
||||||
* const_buffer buf(*i++);
|
* const_buffer buf(*i++);
|
||||||
* s += buffer_size(buf);
|
* s += buf.size();
|
||||||
* }
|
* }
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
|
@ -67,13 +67,6 @@ namespace asio {
|
|||||||
class mutable_buffer;
|
class mutable_buffer;
|
||||||
class const_buffer;
|
class const_buffer;
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
void* buffer_cast_helper(const mutable_buffer&);
|
|
||||||
const void* buffer_cast_helper(const const_buffer&);
|
|
||||||
std::size_t buffer_size_helper(const mutable_buffer&);
|
|
||||||
std::size_t buffer_size_helper(const const_buffer&);
|
|
||||||
} // namespace detail
|
|
||||||
|
|
||||||
/// Holds a buffer that can be modified.
|
/// Holds a buffer that can be modified.
|
||||||
/**
|
/**
|
||||||
* The mutable_buffer class provides a safe representation of a buffer that can
|
* The mutable_buffer class provides a safe representation of a buffer that can
|
||||||
@ -82,16 +75,16 @@ std::size_t buffer_size_helper(const const_buffer&);
|
|||||||
*
|
*
|
||||||
* @par Accessing Buffer Contents
|
* @par Accessing Buffer Contents
|
||||||
*
|
*
|
||||||
* The contents of a buffer may be accessed using the @ref buffer_size
|
* The contents of a buffer may be accessed using the @c data() and @c size()
|
||||||
* and @ref buffer_cast functions:
|
* member functions:
|
||||||
*
|
*
|
||||||
* @code asio::mutable_buffer b1 = ...;
|
* @code asio::mutable_buffer b1 = ...;
|
||||||
* std::size_t s1 = asio::buffer_size(b1);
|
* std::size_t s1 = b1.size();
|
||||||
* unsigned char* p1 = asio::buffer_cast<unsigned char*>(b1);
|
* unsigned char* p1 = static_cast<unsigned char*>(b1.data());
|
||||||
* @endcode
|
* @endcode
|
||||||
*
|
*
|
||||||
* The asio::buffer_cast function permits violations of type safety, so
|
* The @c data() member function permits violations of type safety, so uses of
|
||||||
* uses of it in application code should be carefully considered.
|
* it in application code should be carefully considered.
|
||||||
*/
|
*/
|
||||||
class mutable_buffer
|
class mutable_buffer
|
||||||
{
|
{
|
||||||
@ -125,12 +118,23 @@ public:
|
|||||||
}
|
}
|
||||||
#endif // ASIO_ENABLE_BUFFER_DEBUGGING
|
#endif // ASIO_ENABLE_BUFFER_DEBUGGING
|
||||||
|
|
||||||
private:
|
/// Get a pointer to the beginning of the memory range.
|
||||||
friend void* asio::detail::buffer_cast_helper(
|
void* data() const
|
||||||
const mutable_buffer& b);
|
{
|
||||||
friend std::size_t asio::detail::buffer_size_helper(
|
#if defined(ASIO_ENABLE_BUFFER_DEBUGGING)
|
||||||
const mutable_buffer& b);
|
if (size_ && debug_check_)
|
||||||
|
debug_check_();
|
||||||
|
#endif // ASIO_ENABLE_BUFFER_DEBUGGING
|
||||||
|
return data_;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the size of the memory range.
|
||||||
|
std::size_t size() const
|
||||||
|
{
|
||||||
|
return size_;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
void* data_;
|
void* data_;
|
||||||
std::size_t size_;
|
std::size_t size_;
|
||||||
|
|
||||||
@ -139,24 +143,6 @@ private:
|
|||||||
#endif // ASIO_ENABLE_BUFFER_DEBUGGING
|
#endif // ASIO_ENABLE_BUFFER_DEBUGGING
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
inline void* buffer_cast_helper(const mutable_buffer& b)
|
|
||||||
{
|
|
||||||
#if defined(ASIO_ENABLE_BUFFER_DEBUGGING)
|
|
||||||
if (b.size_ && b.debug_check_)
|
|
||||||
b.debug_check_();
|
|
||||||
#endif // ASIO_ENABLE_BUFFER_DEBUGGING
|
|
||||||
return b.data_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::size_t buffer_size_helper(const mutable_buffer& b)
|
|
||||||
{
|
|
||||||
return b.size_;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace detail
|
|
||||||
|
|
||||||
/// Adapts a single modifiable buffer so that it meets the requirements of the
|
/// Adapts a single modifiable buffer so that it meets the requirements of the
|
||||||
/// MutableBufferSequence concept.
|
/// MutableBufferSequence concept.
|
||||||
class mutable_buffers_1
|
class mutable_buffers_1
|
||||||
@ -202,16 +188,16 @@ public:
|
|||||||
*
|
*
|
||||||
* @par Accessing Buffer Contents
|
* @par Accessing Buffer Contents
|
||||||
*
|
*
|
||||||
* The contents of a buffer may be accessed using the @ref buffer_size
|
* The contents of a buffer may be accessed using the @c data() and @c size()
|
||||||
* and @ref buffer_cast functions:
|
* member functions:
|
||||||
*
|
*
|
||||||
* @code asio::const_buffer b1 = ...;
|
* @code asio::const_buffer b1 = ...;
|
||||||
* std::size_t s1 = asio::buffer_size(b1);
|
* std::size_t s1 = b1.size();
|
||||||
* const unsigned char* p1 = asio::buffer_cast<const unsigned char*>(b1);
|
* const unsigned char* p1 = static_cast<const unsigned char*>(b1.data());
|
||||||
* @endcode
|
* @endcode
|
||||||
*
|
*
|
||||||
* The asio::buffer_cast function permits violations of type safety, so
|
* The @c data() member function permits violations of type safety, so uses of
|
||||||
* uses of it in application code should be carefully considered.
|
* it in application code should be carefully considered.
|
||||||
*/
|
*/
|
||||||
class const_buffer
|
class const_buffer
|
||||||
{
|
{
|
||||||
@ -232,8 +218,8 @@ public:
|
|||||||
|
|
||||||
/// Construct a non-modifiable buffer from a modifiable one.
|
/// Construct a non-modifiable buffer from a modifiable one.
|
||||||
const_buffer(const mutable_buffer& b)
|
const_buffer(const mutable_buffer& b)
|
||||||
: data_(asio::detail::buffer_cast_helper(b)),
|
: data_(b.data()),
|
||||||
size_(asio::detail::buffer_size_helper(b))
|
size_(b.size())
|
||||||
#if defined(ASIO_ENABLE_BUFFER_DEBUGGING)
|
#if defined(ASIO_ENABLE_BUFFER_DEBUGGING)
|
||||||
, debug_check_(b.get_debug_check())
|
, debug_check_(b.get_debug_check())
|
||||||
#endif // ASIO_ENABLE_BUFFER_DEBUGGING
|
#endif // ASIO_ENABLE_BUFFER_DEBUGGING
|
||||||
@ -255,12 +241,23 @@ public:
|
|||||||
}
|
}
|
||||||
#endif // ASIO_ENABLE_BUFFER_DEBUGGING
|
#endif // ASIO_ENABLE_BUFFER_DEBUGGING
|
||||||
|
|
||||||
private:
|
/// Get a pointer to the beginning of the memory range.
|
||||||
friend const void* asio::detail::buffer_cast_helper(
|
const void* data() const
|
||||||
const const_buffer& b);
|
{
|
||||||
friend std::size_t asio::detail::buffer_size_helper(
|
#if defined(ASIO_ENABLE_BUFFER_DEBUGGING)
|
||||||
const const_buffer& b);
|
if (size_ && debug_check_)
|
||||||
|
debug_check_();
|
||||||
|
#endif // ASIO_ENABLE_BUFFER_DEBUGGING
|
||||||
|
return data_;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the size of the memory range.
|
||||||
|
std::size_t size() const
|
||||||
|
{
|
||||||
|
return size_;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
const void* data_;
|
const void* data_;
|
||||||
std::size_t size_;
|
std::size_t size_;
|
||||||
|
|
||||||
@ -269,24 +266,6 @@ private:
|
|||||||
#endif // ASIO_ENABLE_BUFFER_DEBUGGING
|
#endif // ASIO_ENABLE_BUFFER_DEBUGGING
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
inline const void* buffer_cast_helper(const const_buffer& b)
|
|
||||||
{
|
|
||||||
#if defined(ASIO_ENABLE_BUFFER_DEBUGGING)
|
|
||||||
if (b.size_ && b.debug_check_)
|
|
||||||
b.debug_check_();
|
|
||||||
#endif // ASIO_ENABLE_BUFFER_DEBUGGING
|
|
||||||
return b.data_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::size_t buffer_size_helper(const const_buffer& b)
|
|
||||||
{
|
|
||||||
return b.size_;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace detail
|
|
||||||
|
|
||||||
/// Adapts a single non-modifiable buffer so that it meets the requirements of
|
/// Adapts a single non-modifiable buffer so that it meets the requirements of
|
||||||
/// the ConstBufferSequence concept.
|
/// the ConstBufferSequence concept.
|
||||||
class const_buffers_1
|
class const_buffers_1
|
||||||
@ -398,25 +377,25 @@ private:
|
|||||||
/// Get the number of bytes in a modifiable buffer.
|
/// Get the number of bytes in a modifiable buffer.
|
||||||
inline std::size_t buffer_size(const mutable_buffer& b)
|
inline std::size_t buffer_size(const mutable_buffer& b)
|
||||||
{
|
{
|
||||||
return detail::buffer_size_helper(b);
|
return b.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the number of bytes in a modifiable buffer.
|
/// Get the number of bytes in a modifiable buffer.
|
||||||
inline std::size_t buffer_size(const mutable_buffers_1& b)
|
inline std::size_t buffer_size(const mutable_buffers_1& b)
|
||||||
{
|
{
|
||||||
return detail::buffer_size_helper(b);
|
return b.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the number of bytes in a non-modifiable buffer.
|
/// Get the number of bytes in a non-modifiable buffer.
|
||||||
inline std::size_t buffer_size(const const_buffer& b)
|
inline std::size_t buffer_size(const const_buffer& b)
|
||||||
{
|
{
|
||||||
return detail::buffer_size_helper(b);
|
return b.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the number of bytes in a non-modifiable buffer.
|
/// Get the number of bytes in a non-modifiable buffer.
|
||||||
inline std::size_t buffer_size(const const_buffers_1& b)
|
inline std::size_t buffer_size(const const_buffers_1& b)
|
||||||
{
|
{
|
||||||
return detail::buffer_size_helper(b);
|
return b.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the total number of bytes in a buffer sequence.
|
/// Get the total number of bytes in a buffer sequence.
|
||||||
@ -435,17 +414,20 @@ inline std::size_t buffer_size(const BufferSequence& b,
|
|||||||
typename BufferSequence::const_iterator iter = b.begin();
|
typename BufferSequence::const_iterator iter = b.begin();
|
||||||
typename BufferSequence::const_iterator end = b.end();
|
typename BufferSequence::const_iterator end = b.end();
|
||||||
for (; iter != end; ++iter)
|
for (; iter != end; ++iter)
|
||||||
total_buffer_size += detail::buffer_size_helper(*iter);
|
total_buffer_size += iter->size();
|
||||||
|
|
||||||
return total_buffer_size;
|
return total_buffer_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@}*/
|
/*@}*/
|
||||||
|
|
||||||
|
#if !defined(ASIO_NO_DEPRECATED)
|
||||||
|
|
||||||
/** @defgroup buffer_cast asio::buffer_cast
|
/** @defgroup buffer_cast asio::buffer_cast
|
||||||
*
|
*
|
||||||
* @brief The asio::buffer_cast function is used to obtain a pointer to
|
* @brief (Deprecated: Use the @c data() member function.) The
|
||||||
* the underlying memory region associated with a buffer.
|
* asio::buffer_cast function is used to obtain a pointer to the underlying
|
||||||
|
* memory region associated with a buffer.
|
||||||
*
|
*
|
||||||
* @par Examples:
|
* @par Examples:
|
||||||
*
|
*
|
||||||
@ -468,28 +450,30 @@ inline std::size_t buffer_size(const BufferSequence& b,
|
|||||||
template <typename PointerToPodType>
|
template <typename PointerToPodType>
|
||||||
inline PointerToPodType buffer_cast(const mutable_buffer& b)
|
inline PointerToPodType buffer_cast(const mutable_buffer& b)
|
||||||
{
|
{
|
||||||
return static_cast<PointerToPodType>(detail::buffer_cast_helper(b));
|
return static_cast<PointerToPodType>(b.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Cast a non-modifiable buffer to a specified pointer to POD type.
|
/// Cast a non-modifiable buffer to a specified pointer to POD type.
|
||||||
template <typename PointerToPodType>
|
template <typename PointerToPodType>
|
||||||
inline PointerToPodType buffer_cast(const const_buffer& b)
|
inline PointerToPodType buffer_cast(const const_buffer& b)
|
||||||
{
|
{
|
||||||
return static_cast<PointerToPodType>(detail::buffer_cast_helper(b));
|
return static_cast<PointerToPodType>(b.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@}*/
|
/*@}*/
|
||||||
|
|
||||||
|
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||||
|
|
||||||
/// Create a new modifiable buffer that is offset from the start of another.
|
/// Create a new modifiable buffer that is offset from the start of another.
|
||||||
/**
|
/**
|
||||||
* @relates mutable_buffer
|
* @relates mutable_buffer
|
||||||
*/
|
*/
|
||||||
inline mutable_buffer operator+(const mutable_buffer& b, std::size_t start)
|
inline mutable_buffer operator+(const mutable_buffer& b, std::size_t start)
|
||||||
{
|
{
|
||||||
if (start > buffer_size(b))
|
if (start > b.size())
|
||||||
return mutable_buffer();
|
return mutable_buffer();
|
||||||
char* new_data = buffer_cast<char*>(b) + start;
|
char* new_data = static_cast<char*>(b.data()) + start;
|
||||||
std::size_t new_size = buffer_size(b) - start;
|
std::size_t new_size = b.size() - start;
|
||||||
return mutable_buffer(new_data, new_size
|
return mutable_buffer(new_data, new_size
|
||||||
#if defined(ASIO_ENABLE_BUFFER_DEBUGGING)
|
#if defined(ASIO_ENABLE_BUFFER_DEBUGGING)
|
||||||
, b.get_debug_check()
|
, b.get_debug_check()
|
||||||
@ -503,15 +487,7 @@ inline mutable_buffer operator+(const mutable_buffer& b, std::size_t start)
|
|||||||
*/
|
*/
|
||||||
inline mutable_buffer operator+(std::size_t start, const mutable_buffer& b)
|
inline mutable_buffer operator+(std::size_t start, const mutable_buffer& b)
|
||||||
{
|
{
|
||||||
if (start > buffer_size(b))
|
return b + start;
|
||||||
return mutable_buffer();
|
|
||||||
char* new_data = buffer_cast<char*>(b) + start;
|
|
||||||
std::size_t new_size = buffer_size(b) - start;
|
|
||||||
return mutable_buffer(new_data, new_size
|
|
||||||
#if defined(ASIO_ENABLE_BUFFER_DEBUGGING)
|
|
||||||
, b.get_debug_check()
|
|
||||||
#endif // ASIO_ENABLE_BUFFER_DEBUGGING
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new non-modifiable buffer that is offset from the start of another.
|
/// Create a new non-modifiable buffer that is offset from the start of another.
|
||||||
@ -520,10 +496,10 @@ inline mutable_buffer operator+(std::size_t start, const mutable_buffer& b)
|
|||||||
*/
|
*/
|
||||||
inline const_buffer operator+(const const_buffer& b, std::size_t start)
|
inline const_buffer operator+(const const_buffer& b, std::size_t start)
|
||||||
{
|
{
|
||||||
if (start > buffer_size(b))
|
if (start > b.size())
|
||||||
return const_buffer();
|
return const_buffer();
|
||||||
const char* new_data = buffer_cast<const char*>(b) + start;
|
const char* new_data = static_cast<const char*>(b.data()) + start;
|
||||||
std::size_t new_size = buffer_size(b) - start;
|
std::size_t new_size = b.size() - start;
|
||||||
return const_buffer(new_data, new_size
|
return const_buffer(new_data, new_size
|
||||||
#if defined(ASIO_ENABLE_BUFFER_DEBUGGING)
|
#if defined(ASIO_ENABLE_BUFFER_DEBUGGING)
|
||||||
, b.get_debug_check()
|
, b.get_debug_check()
|
||||||
@ -537,15 +513,7 @@ inline const_buffer operator+(const const_buffer& b, std::size_t start)
|
|||||||
*/
|
*/
|
||||||
inline const_buffer operator+(std::size_t start, const const_buffer& b)
|
inline const_buffer operator+(std::size_t start, const const_buffer& b)
|
||||||
{
|
{
|
||||||
if (start > buffer_size(b))
|
return b + start;
|
||||||
return const_buffer();
|
|
||||||
const char* new_data = buffer_cast<const char*>(b) + start;
|
|
||||||
std::size_t new_size = buffer_size(b) - start;
|
|
||||||
return const_buffer(new_data, new_size
|
|
||||||
#if defined(ASIO_ENABLE_BUFFER_DEBUGGING)
|
|
||||||
, b.get_debug_check()
|
|
||||||
#endif // ASIO_ENABLE_BUFFER_DEBUGGING
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(ASIO_ENABLE_BUFFER_DEBUGGING)
|
#if defined(ASIO_ENABLE_BUFFER_DEBUGGING)
|
||||||
@ -630,24 +598,24 @@ private:
|
|||||||
*
|
*
|
||||||
* @par Accessing Buffer Contents
|
* @par Accessing Buffer Contents
|
||||||
*
|
*
|
||||||
* The contents of a buffer may be accessed using the @ref buffer_size and
|
* The contents of a buffer may be accessed using the @c data() and @c size()
|
||||||
* @ref buffer_cast functions:
|
* member functions:
|
||||||
*
|
*
|
||||||
* @code asio::mutable_buffer b1 = ...;
|
* @code asio::mutable_buffer b1 = ...;
|
||||||
* std::size_t s1 = asio::buffer_size(b1);
|
* std::size_t s1 = b1.size();
|
||||||
* unsigned char* p1 = asio::buffer_cast<unsigned char*>(b1);
|
* unsigned char* p1 = static_cast<unsigned char*>(b1.data());
|
||||||
*
|
*
|
||||||
* asio::const_buffer b2 = ...;
|
* asio::const_buffer b2 = ...;
|
||||||
* std::size_t s2 = asio::buffer_size(b2);
|
* std::size_t s2 = b2.size();
|
||||||
* const void* p2 = asio::buffer_cast<const void*>(b2); @endcode
|
* const void* p2 = b2.data(); @endcode
|
||||||
*
|
*
|
||||||
* The asio::buffer_cast function permits violations of type safety, so
|
* The @c data() member function permits violations of type safety, so
|
||||||
* uses of it in application code should be carefully considered.
|
* uses of it in application code should be carefully considered.
|
||||||
*
|
*
|
||||||
* For convenience, the @ref buffer_size function also works on buffer
|
* For convenience, a @ref buffer_size function is provided that works with
|
||||||
* sequences (that is, types meeting the ConstBufferSequence or
|
* both buffers and buffer sequences (that is, types meeting the
|
||||||
* MutableBufferSequence type requirements). In this case, the function returns
|
* ConstBufferSequence or MutableBufferSequence type requirements). In this
|
||||||
* the total size of all buffers in the sequence.
|
* case, the function returns the total size of all buffers in the sequence.
|
||||||
*
|
*
|
||||||
* @par Buffer Copying
|
* @par Buffer Copying
|
||||||
*
|
*
|
||||||
@ -757,16 +725,16 @@ inline mutable_buffers_1 buffer(const mutable_buffer& b)
|
|||||||
/**
|
/**
|
||||||
* @returns A mutable_buffers_1 value equivalent to:
|
* @returns A mutable_buffers_1 value equivalent to:
|
||||||
* @code mutable_buffers_1(
|
* @code mutable_buffers_1(
|
||||||
* buffer_cast<void*>(b),
|
* b.data(),
|
||||||
* min(buffer_size(b), max_size_in_bytes)); @endcode
|
* min(b.size(), max_size_in_bytes)); @endcode
|
||||||
*/
|
*/
|
||||||
inline mutable_buffers_1 buffer(const mutable_buffer& b,
|
inline mutable_buffers_1 buffer(const mutable_buffer& b,
|
||||||
std::size_t max_size_in_bytes)
|
std::size_t max_size_in_bytes)
|
||||||
{
|
{
|
||||||
return mutable_buffers_1(
|
return mutable_buffers_1(
|
||||||
mutable_buffer(buffer_cast<void*>(b),
|
mutable_buffer(b.data(),
|
||||||
buffer_size(b) < max_size_in_bytes
|
b.size() < max_size_in_bytes
|
||||||
? buffer_size(b) : max_size_in_bytes
|
? b.size() : max_size_in_bytes
|
||||||
#if defined(ASIO_ENABLE_BUFFER_DEBUGGING)
|
#if defined(ASIO_ENABLE_BUFFER_DEBUGGING)
|
||||||
, b.get_debug_check()
|
, b.get_debug_check()
|
||||||
#endif // ASIO_ENABLE_BUFFER_DEBUGGING
|
#endif // ASIO_ENABLE_BUFFER_DEBUGGING
|
||||||
@ -786,16 +754,16 @@ inline const_buffers_1 buffer(const const_buffer& b)
|
|||||||
/**
|
/**
|
||||||
* @returns A const_buffers_1 value equivalent to:
|
* @returns A const_buffers_1 value equivalent to:
|
||||||
* @code const_buffers_1(
|
* @code const_buffers_1(
|
||||||
* buffer_cast<const void*>(b),
|
* b.data(),
|
||||||
* min(buffer_size(b), max_size_in_bytes)); @endcode
|
* min(b.size(), max_size_in_bytes)); @endcode
|
||||||
*/
|
*/
|
||||||
inline const_buffers_1 buffer(const const_buffer& b,
|
inline const_buffers_1 buffer(const const_buffer& b,
|
||||||
std::size_t max_size_in_bytes)
|
std::size_t max_size_in_bytes)
|
||||||
{
|
{
|
||||||
return const_buffers_1(
|
return const_buffers_1(
|
||||||
const_buffer(buffer_cast<const void*>(b),
|
const_buffer(b.data(),
|
||||||
buffer_size(b) < max_size_in_bytes
|
b.size() < max_size_in_bytes
|
||||||
? buffer_size(b) : max_size_in_bytes
|
? b.size() : max_size_in_bytes
|
||||||
#if defined(ASIO_ENABLE_BUFFER_DEBUGGING)
|
#if defined(ASIO_ENABLE_BUFFER_DEBUGGING)
|
||||||
, b.get_debug_check()
|
, b.get_debug_check()
|
||||||
#endif // ASIO_ENABLE_BUFFER_DEBUGGING
|
#endif // ASIO_ENABLE_BUFFER_DEBUGGING
|
||||||
@ -806,7 +774,8 @@ inline const_buffers_1 buffer(const const_buffer& b,
|
|||||||
/**
|
/**
|
||||||
* @returns <tt>mutable_buffers_1(data, size_in_bytes)</tt>.
|
* @returns <tt>mutable_buffers_1(data, size_in_bytes)</tt>.
|
||||||
*/
|
*/
|
||||||
inline mutable_buffers_1 buffer(void* data, std::size_t size_in_bytes)
|
inline mutable_buffers_1 buffer(void* data,
|
||||||
|
std::size_t size_in_bytes)
|
||||||
{
|
{
|
||||||
return mutable_buffers_1(mutable_buffer(data, size_in_bytes));
|
return mutable_buffers_1(mutable_buffer(data, size_in_bytes));
|
||||||
}
|
}
|
||||||
@ -1744,10 +1713,10 @@ inline std::size_t buffer_copy(const mutable_buffer& target,
|
|||||||
const const_buffer& source)
|
const const_buffer& source)
|
||||||
{
|
{
|
||||||
using namespace std; // For memcpy.
|
using namespace std; // For memcpy.
|
||||||
std::size_t target_size = buffer_size(target);
|
std::size_t target_size = target.size();
|
||||||
std::size_t source_size = buffer_size(source);
|
std::size_t source_size = source.size();
|
||||||
std::size_t n = target_size < source_size ? target_size : source_size;
|
std::size_t n = target_size < source_size ? target_size : source_size;
|
||||||
memcpy(buffer_cast<void*>(target), buffer_cast<const void*>(source), n);
|
memcpy(target.data(), source.data(), n);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1860,7 +1829,7 @@ std::size_t buffer_copy(const mutable_buffer& target,
|
|||||||
typename ConstBufferSequence::const_iterator source_end = source.end();
|
typename ConstBufferSequence::const_iterator source_end = source.end();
|
||||||
|
|
||||||
for (mutable_buffer target_buffer(target);
|
for (mutable_buffer target_buffer(target);
|
||||||
buffer_size(target_buffer) && source_iter != source_end; ++source_iter)
|
target_buffer.size() && source_iter != source_end; ++source_iter)
|
||||||
{
|
{
|
||||||
const_buffer source_buffer(*source_iter);
|
const_buffer source_buffer(*source_iter);
|
||||||
std::size_t bytes_copied = buffer_copy(target_buffer, source_buffer);
|
std::size_t bytes_copied = buffer_copy(target_buffer, source_buffer);
|
||||||
@ -2037,7 +2006,7 @@ std::size_t buffer_copy(const MutableBufferSequence& target,
|
|||||||
typename MutableBufferSequence::const_iterator target_end = target.end();
|
typename MutableBufferSequence::const_iterator target_end = target.end();
|
||||||
|
|
||||||
for (const_buffer source_buffer(source);
|
for (const_buffer source_buffer(source);
|
||||||
buffer_size(source_buffer) && target_iter != target_end; ++target_iter)
|
source_buffer.size() && target_iter != target_end; ++target_iter)
|
||||||
{
|
{
|
||||||
mutable_buffer target_buffer(*target_iter);
|
mutable_buffer target_buffer(*target_iter);
|
||||||
std::size_t bytes_copied = buffer_copy(target_buffer, source_buffer);
|
std::size_t bytes_copied = buffer_copy(target_buffer, source_buffer);
|
||||||
@ -2185,7 +2154,7 @@ std::size_t buffer_copy(const MutableBufferSequence& target,
|
|||||||
std::size_t bytes_copied = buffer_copy(target_buffer, source_buffer);
|
std::size_t bytes_copied = buffer_copy(target_buffer, source_buffer);
|
||||||
total_bytes_copied += bytes_copied;
|
total_bytes_copied += bytes_copied;
|
||||||
|
|
||||||
if (bytes_copied == buffer_size(target_buffer))
|
if (bytes_copied == target_buffer.size())
|
||||||
{
|
{
|
||||||
++target_iter;
|
++target_iter;
|
||||||
target_buffer_offset = 0;
|
target_buffer_offset = 0;
|
||||||
@ -2193,7 +2162,7 @@ std::size_t buffer_copy(const MutableBufferSequence& target,
|
|||||||
else
|
else
|
||||||
target_buffer_offset += bytes_copied;
|
target_buffer_offset += bytes_copied;
|
||||||
|
|
||||||
if (bytes_copied == buffer_size(source_buffer))
|
if (bytes_copied == source_buffer.size())
|
||||||
{
|
{
|
||||||
++source_iter;
|
++source_iter;
|
||||||
source_buffer_offset = 0;
|
source_buffer_offset = 0;
|
||||||
@ -2702,7 +2671,7 @@ std::size_t buffer_copy(const MutableBufferSequence& target,
|
|||||||
source_buffer, max_bytes_to_copy - total_bytes_copied);
|
source_buffer, max_bytes_to_copy - total_bytes_copied);
|
||||||
total_bytes_copied += bytes_copied;
|
total_bytes_copied += bytes_copied;
|
||||||
|
|
||||||
if (bytes_copied == buffer_size(target_buffer))
|
if (bytes_copied == target_buffer.size())
|
||||||
{
|
{
|
||||||
++target_iter;
|
++target_iter;
|
||||||
target_buffer_offset = 0;
|
target_buffer_offset = 0;
|
||||||
@ -2710,7 +2679,7 @@ std::size_t buffer_copy(const MutableBufferSequence& target,
|
|||||||
else
|
else
|
||||||
target_buffer_offset += bytes_copied;
|
target_buffer_offset += bytes_copied;
|
||||||
|
|
||||||
if (bytes_copied == buffer_size(source_buffer))
|
if (bytes_copied == source_buffer.size())
|
||||||
{
|
{
|
||||||
++source_iter;
|
++source_iter;
|
||||||
source_buffer_offset = 0;
|
source_buffer_offset = 0;
|
||||||
|
@ -136,7 +136,7 @@ public:
|
|||||||
while (new_iter.current_ != new_iter.end_)
|
while (new_iter.current_ != new_iter.end_)
|
||||||
{
|
{
|
||||||
new_iter.current_buffer_ = *new_iter.current_;
|
new_iter.current_buffer_ = *new_iter.current_;
|
||||||
if (asio::buffer_size(new_iter.current_buffer_) > 0)
|
if (new_iter.current_buffer_.size() > 0)
|
||||||
break;
|
break;
|
||||||
++new_iter.current_;
|
++new_iter.current_;
|
||||||
}
|
}
|
||||||
@ -156,7 +156,7 @@ public:
|
|||||||
while (new_iter.current_ != new_iter.end_)
|
while (new_iter.current_ != new_iter.end_)
|
||||||
{
|
{
|
||||||
buffer_type buffer = *new_iter.current_;
|
buffer_type buffer = *new_iter.current_;
|
||||||
new_iter.position_ += asio::buffer_size(buffer);
|
new_iter.position_ += buffer.size();
|
||||||
++new_iter.current_;
|
++new_iter.current_;
|
||||||
}
|
}
|
||||||
return new_iter;
|
return new_iter;
|
||||||
@ -300,7 +300,8 @@ private:
|
|||||||
// Dereference the iterator.
|
// Dereference the iterator.
|
||||||
reference dereference() const
|
reference dereference() const
|
||||||
{
|
{
|
||||||
return buffer_cast<pointer>(current_buffer_)[current_buffer_position_];
|
return static_cast<pointer>(
|
||||||
|
current_buffer_.data())[current_buffer_position_];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compare two iterators for equality.
|
// Compare two iterators for equality.
|
||||||
@ -317,7 +318,7 @@ private:
|
|||||||
|
|
||||||
// Check if the increment can be satisfied by the current buffer.
|
// Check if the increment can be satisfied by the current buffer.
|
||||||
++current_buffer_position_;
|
++current_buffer_position_;
|
||||||
if (current_buffer_position_ != asio::buffer_size(current_buffer_))
|
if (current_buffer_position_ != current_buffer_.size())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Find the next non-empty buffer.
|
// Find the next non-empty buffer.
|
||||||
@ -326,7 +327,7 @@ private:
|
|||||||
while (current_ != end_)
|
while (current_ != end_)
|
||||||
{
|
{
|
||||||
current_buffer_ = *current_;
|
current_buffer_ = *current_;
|
||||||
if (asio::buffer_size(current_buffer_) > 0)
|
if (current_buffer_.size() > 0)
|
||||||
return;
|
return;
|
||||||
++current_;
|
++current_;
|
||||||
}
|
}
|
||||||
@ -351,7 +352,7 @@ private:
|
|||||||
{
|
{
|
||||||
--iter;
|
--iter;
|
||||||
buffer_type buffer = *iter;
|
buffer_type buffer = *iter;
|
||||||
std::size_t buffer_size = asio::buffer_size(buffer);
|
std::size_t buffer_size = buffer.size();
|
||||||
if (buffer_size > 0)
|
if (buffer_size > 0)
|
||||||
{
|
{
|
||||||
current_ = iter;
|
current_ = iter;
|
||||||
@ -371,8 +372,7 @@ private:
|
|||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
std::ptrdiff_t current_buffer_balance
|
std::ptrdiff_t current_buffer_balance
|
||||||
= asio::buffer_size(current_buffer_)
|
= current_buffer_.size() - current_buffer_position_;
|
||||||
- current_buffer_position_;
|
|
||||||
|
|
||||||
// Check if the advance can be satisfied by the current buffer.
|
// Check if the advance can be satisfied by the current buffer.
|
||||||
if (current_buffer_balance > n)
|
if (current_buffer_balance > n)
|
||||||
@ -431,7 +431,7 @@ private:
|
|||||||
{
|
{
|
||||||
--iter;
|
--iter;
|
||||||
buffer_type buffer = *iter;
|
buffer_type buffer = *iter;
|
||||||
std::size_t buffer_size = asio::buffer_size(buffer);
|
std::size_t buffer_size = buffer.size();
|
||||||
if (buffer_size > 0)
|
if (buffer_size > 0)
|
||||||
{
|
{
|
||||||
current_ = iter;
|
current_ = iter;
|
||||||
|
@ -50,15 +50,15 @@ protected:
|
|||||||
static void init_native_buffer(WSABUF& buf,
|
static void init_native_buffer(WSABUF& buf,
|
||||||
const asio::mutable_buffer& buffer)
|
const asio::mutable_buffer& buffer)
|
||||||
{
|
{
|
||||||
buf.buf = asio::buffer_cast<char*>(buffer);
|
buf.buf = static_cast<char*>(buffer.data());
|
||||||
buf.len = static_cast<ULONG>(asio::buffer_size(buffer));
|
buf.len = static_cast<ULONG>(buffer.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_native_buffer(WSABUF& buf,
|
static void init_native_buffer(WSABUF& buf,
|
||||||
const asio::const_buffer& buffer)
|
const asio::const_buffer& buffer)
|
||||||
{
|
{
|
||||||
buf.buf = const_cast<char*>(asio::buffer_cast<const char*>(buffer));
|
buf.buf = const_cast<char*>(static_cast<const char*>(buffer.data()));
|
||||||
buf.len = static_cast<ULONG>(asio::buffer_size(buffer));
|
buf.len = static_cast<ULONG>(buffer.size());
|
||||||
}
|
}
|
||||||
#else // defined(ASIO_WINDOWS) || defined(__CYGWIN__)
|
#else // defined(ASIO_WINDOWS) || defined(__CYGWIN__)
|
||||||
// The maximum number of buffers to support in a single operation.
|
// The maximum number of buffers to support in a single operation.
|
||||||
@ -80,16 +80,15 @@ protected:
|
|||||||
static void init_native_buffer(iovec& iov,
|
static void init_native_buffer(iovec& iov,
|
||||||
const asio::mutable_buffer& buffer)
|
const asio::mutable_buffer& buffer)
|
||||||
{
|
{
|
||||||
init_iov_base(iov.iov_base, asio::buffer_cast<void*>(buffer));
|
init_iov_base(iov.iov_base, buffer.data());
|
||||||
iov.iov_len = asio::buffer_size(buffer);
|
iov.iov_len = buffer.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_native_buffer(iovec& iov,
|
static void init_native_buffer(iovec& iov,
|
||||||
const asio::const_buffer& buffer)
|
const asio::const_buffer& buffer)
|
||||||
{
|
{
|
||||||
init_iov_base(iov.iov_base, const_cast<void*>(
|
init_iov_base(iov.iov_base, const_cast<void*>(buffer.data()));
|
||||||
asio::buffer_cast<const void*>(buffer)));
|
iov.iov_len = buffer.size();
|
||||||
iov.iov_len = asio::buffer_size(buffer);
|
|
||||||
}
|
}
|
||||||
#endif // defined(ASIO_WINDOWS) || defined(__CYGWIN__)
|
#endif // defined(ASIO_WINDOWS) || defined(__CYGWIN__)
|
||||||
};
|
};
|
||||||
@ -109,7 +108,7 @@ public:
|
|||||||
{
|
{
|
||||||
Buffer buffer(*iter);
|
Buffer buffer(*iter);
|
||||||
init_native_buffer(buffers_[count_], buffer);
|
init_native_buffer(buffers_[count_], buffer);
|
||||||
total_buffer_size_ += asio::buffer_size(buffer);
|
total_buffer_size_ += buffer.size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +133,7 @@ public:
|
|||||||
typename Buffers::const_iterator end = buffer_sequence.end();
|
typename Buffers::const_iterator end = buffer_sequence.end();
|
||||||
std::size_t i = 0;
|
std::size_t i = 0;
|
||||||
for (; iter != end && i < max_buffers; ++iter, ++i)
|
for (; iter != end && i < max_buffers; ++iter, ++i)
|
||||||
if (asio::buffer_size(Buffer(*iter)) > 0)
|
if (Buffer(*iter).size() > 0)
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -146,7 +145,7 @@ public:
|
|||||||
for (; iter != end; ++iter)
|
for (; iter != end; ++iter)
|
||||||
{
|
{
|
||||||
Buffer buffer(*iter);
|
Buffer buffer(*iter);
|
||||||
asio::buffer_cast<const void*>(buffer);
|
buffer.data();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +156,7 @@ public:
|
|||||||
for (; iter != end; ++iter)
|
for (; iter != end; ++iter)
|
||||||
{
|
{
|
||||||
Buffer buffer(*iter);
|
Buffer buffer(*iter);
|
||||||
if (asio::buffer_size(buffer) != 0)
|
if (buffer.size() != 0)
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
return Buffer();
|
return Buffer();
|
||||||
@ -178,7 +177,7 @@ public:
|
|||||||
const asio::mutable_buffers_1& buffer_sequence)
|
const asio::mutable_buffers_1& buffer_sequence)
|
||||||
{
|
{
|
||||||
init_native_buffer(buffer_, Buffer(buffer_sequence));
|
init_native_buffer(buffer_, Buffer(buffer_sequence));
|
||||||
total_buffer_size_ = asio::buffer_size(buffer_sequence);
|
total_buffer_size_ = buffer_sequence.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
native_buffer_type* buffers()
|
native_buffer_type* buffers()
|
||||||
@ -198,12 +197,12 @@ public:
|
|||||||
|
|
||||||
static bool all_empty(const asio::mutable_buffers_1& buffer_sequence)
|
static bool all_empty(const asio::mutable_buffers_1& buffer_sequence)
|
||||||
{
|
{
|
||||||
return asio::buffer_size(buffer_sequence) == 0;
|
return buffer_sequence.size() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void validate(const asio::mutable_buffers_1& buffer_sequence)
|
static void validate(const asio::mutable_buffers_1& buffer_sequence)
|
||||||
{
|
{
|
||||||
asio::buffer_cast<const void*>(buffer_sequence);
|
buffer_sequence.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Buffer first(const asio::mutable_buffers_1& buffer_sequence)
|
static Buffer first(const asio::mutable_buffers_1& buffer_sequence)
|
||||||
@ -225,7 +224,7 @@ public:
|
|||||||
const asio::const_buffers_1& buffer_sequence)
|
const asio::const_buffers_1& buffer_sequence)
|
||||||
{
|
{
|
||||||
init_native_buffer(buffer_, Buffer(buffer_sequence));
|
init_native_buffer(buffer_, Buffer(buffer_sequence));
|
||||||
total_buffer_size_ = asio::buffer_size(buffer_sequence);
|
total_buffer_size_ = buffer_sequence.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
native_buffer_type* buffers()
|
native_buffer_type* buffers()
|
||||||
@ -245,12 +244,12 @@ public:
|
|||||||
|
|
||||||
static bool all_empty(const asio::const_buffers_1& buffer_sequence)
|
static bool all_empty(const asio::const_buffers_1& buffer_sequence)
|
||||||
{
|
{
|
||||||
return asio::buffer_size(buffer_sequence) == 0;
|
return buffer_sequence.size() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void validate(const asio::const_buffers_1& buffer_sequence)
|
static void validate(const asio::const_buffers_1& buffer_sequence)
|
||||||
{
|
{
|
||||||
asio::buffer_cast<const void*>(buffer_sequence);
|
buffer_sequence.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Buffer first(const asio::const_buffers_1& buffer_sequence)
|
static Buffer first(const asio::const_buffers_1& buffer_sequence)
|
||||||
@ -273,8 +272,7 @@ public:
|
|||||||
{
|
{
|
||||||
init_native_buffer(buffers_[0], Buffer(buffer_sequence[0]));
|
init_native_buffer(buffers_[0], Buffer(buffer_sequence[0]));
|
||||||
init_native_buffer(buffers_[1], Buffer(buffer_sequence[1]));
|
init_native_buffer(buffers_[1], Buffer(buffer_sequence[1]));
|
||||||
total_buffer_size_ = asio::buffer_size(buffer_sequence[0])
|
total_buffer_size_ = buffer_sequence[0].size() + buffer_sequence[1].size();
|
||||||
+ asio::buffer_size(buffer_sequence[1]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
native_buffer_type* buffers()
|
native_buffer_type* buffers()
|
||||||
@ -294,19 +292,18 @@ public:
|
|||||||
|
|
||||||
static bool all_empty(const boost::array<Elem, 2>& buffer_sequence)
|
static bool all_empty(const boost::array<Elem, 2>& buffer_sequence)
|
||||||
{
|
{
|
||||||
return asio::buffer_size(buffer_sequence[0]) == 0
|
return buffer_sequence[0].size() == 0 && buffer_sequence[1].size() == 0;
|
||||||
&& asio::buffer_size(buffer_sequence[1]) == 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void validate(const boost::array<Elem, 2>& buffer_sequence)
|
static void validate(const boost::array<Elem, 2>& buffer_sequence)
|
||||||
{
|
{
|
||||||
asio::buffer_cast<const void*>(buffer_sequence[0]);
|
buffer_sequence[0].data();
|
||||||
asio::buffer_cast<const void*>(buffer_sequence[1]);
|
buffer_sequence[1].data();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Buffer first(const boost::array<Elem, 2>& buffer_sequence)
|
static Buffer first(const boost::array<Elem, 2>& buffer_sequence)
|
||||||
{
|
{
|
||||||
return Buffer(asio::buffer_size(buffer_sequence[0]) != 0
|
return Buffer(buffer_sequence[0].size() != 0
|
||||||
? buffer_sequence[0] : buffer_sequence[1]);
|
? buffer_sequence[0] : buffer_sequence[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,8 +324,7 @@ public:
|
|||||||
{
|
{
|
||||||
init_native_buffer(buffers_[0], Buffer(buffer_sequence[0]));
|
init_native_buffer(buffers_[0], Buffer(buffer_sequence[0]));
|
||||||
init_native_buffer(buffers_[1], Buffer(buffer_sequence[1]));
|
init_native_buffer(buffers_[1], Buffer(buffer_sequence[1]));
|
||||||
total_buffer_size_ = asio::buffer_size(buffer_sequence[0])
|
total_buffer_size_ = buffer_sequence[0].size() + buffer_sequence[1].size();
|
||||||
+ asio::buffer_size(buffer_sequence[1]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
native_buffer_type* buffers()
|
native_buffer_type* buffers()
|
||||||
@ -348,19 +344,18 @@ public:
|
|||||||
|
|
||||||
static bool all_empty(const std::array<Elem, 2>& buffer_sequence)
|
static bool all_empty(const std::array<Elem, 2>& buffer_sequence)
|
||||||
{
|
{
|
||||||
return asio::buffer_size(buffer_sequence[0]) == 0
|
return buffer_sequence[0].size() == 0 && buffer_sequence[1].size() == 0;
|
||||||
&& asio::buffer_size(buffer_sequence[1]) == 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void validate(const std::array<Elem, 2>& buffer_sequence)
|
static void validate(const std::array<Elem, 2>& buffer_sequence)
|
||||||
{
|
{
|
||||||
asio::buffer_cast<const void*>(buffer_sequence[0]);
|
buffer_sequence[0].data();
|
||||||
asio::buffer_cast<const void*>(buffer_sequence[1]);
|
buffer_sequence[1].data();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Buffer first(const std::array<Elem, 2>& buffer_sequence)
|
static Buffer first(const std::array<Elem, 2>& buffer_sequence)
|
||||||
{
|
{
|
||||||
return Buffer(asio::buffer_size(buffer_sequence[0]) != 0
|
return Buffer(buffer_sequence[0].size() != 0
|
||||||
? buffer_sequence[0] : buffer_sequence[1]);
|
? buffer_sequence[0] : buffer_sequence[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,13 +113,13 @@ private:
|
|||||||
if (!at_end_)
|
if (!at_end_)
|
||||||
{
|
{
|
||||||
if (begin_remainder_ == end_remainder_
|
if (begin_remainder_ == end_remainder_
|
||||||
|| offset_ + buffer_size(first_) >= max_size_)
|
|| offset_ + first_.size() >= max_size_)
|
||||||
{
|
{
|
||||||
at_end_ = true;
|
at_end_ = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
offset_ += buffer_size(first_);
|
offset_ += first_.size();
|
||||||
first_ = buffer(*begin_remainder_++, max_size_ - offset_);
|
first_ = buffer(*begin_remainder_++, max_size_ - offset_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -130,9 +130,8 @@ private:
|
|||||||
if (at_end_ && other.at_end_)
|
if (at_end_ && other.at_end_)
|
||||||
return true;
|
return true;
|
||||||
return !at_end_ && !other.at_end_
|
return !at_end_ && !other.at_end_
|
||||||
&& buffer_cast<const void*>(first_)
|
&& first_.data() == other.first_.data()
|
||||||
== buffer_cast<const void*>(other.first_)
|
&& first_.size() == other.first_.size()
|
||||||
&& buffer_size(first_) == buffer_size(other.first_)
|
|
||||||
&& begin_remainder_ == other.begin_remainder_
|
&& begin_remainder_ == other.begin_remainder_
|
||||||
&& end_remainder_ == other.end_remainder_;
|
&& end_remainder_ == other.end_remainder_;
|
||||||
}
|
}
|
||||||
@ -228,9 +227,9 @@ public:
|
|||||||
// Remove buffers from the start until the specified size is reached.
|
// Remove buffers from the start until the specified size is reached.
|
||||||
while (size > 0 && !at_end_)
|
while (size > 0 && !at_end_)
|
||||||
{
|
{
|
||||||
if (buffer_size(first_) <= size)
|
if (first_.size() <= size)
|
||||||
{
|
{
|
||||||
size -= buffer_size(first_);
|
size -= first_.size();
|
||||||
if (begin_remainder_ == buffers_.end())
|
if (begin_remainder_ == buffers_.end())
|
||||||
at_end_ = true;
|
at_end_ = true;
|
||||||
else
|
else
|
||||||
@ -244,7 +243,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remove any more empty buffers at the start.
|
// Remove any more empty buffers at the start.
|
||||||
while (!at_end_ && buffer_size(first_) == 0)
|
while (!at_end_ && first_.size() == 0)
|
||||||
{
|
{
|
||||||
if (begin_remainder_ == buffers_.end())
|
if (begin_remainder_ == buffers_.end())
|
||||||
at_end_ = true;
|
at_end_ = true;
|
||||||
|
@ -39,16 +39,16 @@ class winrt_buffer_impl :
|
|||||||
public:
|
public:
|
||||||
explicit winrt_buffer_impl(const asio::const_buffer& b)
|
explicit winrt_buffer_impl(const asio::const_buffer& b)
|
||||||
{
|
{
|
||||||
bytes_ = const_cast<byte*>(asio::buffer_cast<const byte*>(b));
|
bytes_ = const_cast<byte*>(static_cast<const byte*>(b.data()));
|
||||||
length_ = asio::buffer_size(b);
|
length_ = b.size();
|
||||||
capacity_ = asio::buffer_size(b);
|
capacity_ = b.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit winrt_buffer_impl(const asio::mutable_buffer& b)
|
explicit winrt_buffer_impl(const asio::mutable_buffer& b)
|
||||||
{
|
{
|
||||||
bytes_ = const_cast<byte*>(asio::buffer_cast<const byte*>(b));
|
bytes_ = static_cast<byte*>(b.data());
|
||||||
length_ = 0;
|
length_ = 0;
|
||||||
capacity_ = asio::buffer_size(b);
|
capacity_ = b.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
~winrt_buffer_impl()
|
~winrt_buffer_impl()
|
||||||
|
@ -305,7 +305,7 @@ size_t win_iocp_handle_service::do_write(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// A request to write 0 bytes on a handle is a no-op.
|
// A request to write 0 bytes on a handle is a no-op.
|
||||||
if (asio::buffer_size(buffer) == 0)
|
if (buffer.size() == 0)
|
||||||
{
|
{
|
||||||
ec = asio::error_code();
|
ec = asio::error_code();
|
||||||
return 0;
|
return 0;
|
||||||
@ -320,9 +320,8 @@ size_t win_iocp_handle_service::do_write(
|
|||||||
// Write the data.
|
// Write the data.
|
||||||
overlapped.Offset = offset & 0xFFFFFFFF;
|
overlapped.Offset = offset & 0xFFFFFFFF;
|
||||||
overlapped.OffsetHigh = (offset >> 32) & 0xFFFFFFFF;
|
overlapped.OffsetHigh = (offset >> 32) & 0xFFFFFFFF;
|
||||||
BOOL ok = ::WriteFile(impl.handle_,
|
BOOL ok = ::WriteFile(impl.handle_, buffer.data(),
|
||||||
asio::buffer_cast<LPCVOID>(buffer),
|
static_cast<DWORD>(buffer.size()), 0, &overlapped);
|
||||||
static_cast<DWORD>(asio::buffer_size(buffer)), 0, &overlapped);
|
|
||||||
if (!ok)
|
if (!ok)
|
||||||
{
|
{
|
||||||
DWORD last_error = ::GetLastError();
|
DWORD last_error = ::GetLastError();
|
||||||
@ -361,7 +360,7 @@ void win_iocp_handle_service::start_write_op(
|
|||||||
{
|
{
|
||||||
iocp_service_.on_completion(op, asio::error::bad_descriptor);
|
iocp_service_.on_completion(op, asio::error::bad_descriptor);
|
||||||
}
|
}
|
||||||
else if (asio::buffer_size(buffer) == 0)
|
else if (buffer.size() == 0)
|
||||||
{
|
{
|
||||||
// A request to write 0 bytes on a handle is a no-op.
|
// A request to write 0 bytes on a handle is a no-op.
|
||||||
iocp_service_.on_completion(op);
|
iocp_service_.on_completion(op);
|
||||||
@ -371,9 +370,8 @@ void win_iocp_handle_service::start_write_op(
|
|||||||
DWORD bytes_transferred = 0;
|
DWORD bytes_transferred = 0;
|
||||||
op->Offset = offset & 0xFFFFFFFF;
|
op->Offset = offset & 0xFFFFFFFF;
|
||||||
op->OffsetHigh = (offset >> 32) & 0xFFFFFFFF;
|
op->OffsetHigh = (offset >> 32) & 0xFFFFFFFF;
|
||||||
BOOL ok = ::WriteFile(impl.handle_,
|
BOOL ok = ::WriteFile(impl.handle_, buffer.data(),
|
||||||
asio::buffer_cast<LPCVOID>(buffer),
|
static_cast<DWORD>(buffer.size()),
|
||||||
static_cast<DWORD>(asio::buffer_size(buffer)),
|
|
||||||
&bytes_transferred, op);
|
&bytes_transferred, op);
|
||||||
DWORD last_error = ::GetLastError();
|
DWORD last_error = ::GetLastError();
|
||||||
if (!ok && last_error != ERROR_IO_PENDING
|
if (!ok && last_error != ERROR_IO_PENDING
|
||||||
@ -399,7 +397,7 @@ size_t win_iocp_handle_service::do_read(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// A request to read 0 bytes on a stream handle is a no-op.
|
// A request to read 0 bytes on a stream handle is a no-op.
|
||||||
if (asio::buffer_size(buffer) == 0)
|
if (buffer.size() == 0)
|
||||||
{
|
{
|
||||||
ec = asio::error_code();
|
ec = asio::error_code();
|
||||||
return 0;
|
return 0;
|
||||||
@ -414,9 +412,8 @@ size_t win_iocp_handle_service::do_read(
|
|||||||
// Read some data.
|
// Read some data.
|
||||||
overlapped.Offset = offset & 0xFFFFFFFF;
|
overlapped.Offset = offset & 0xFFFFFFFF;
|
||||||
overlapped.OffsetHigh = (offset >> 32) & 0xFFFFFFFF;
|
overlapped.OffsetHigh = (offset >> 32) & 0xFFFFFFFF;
|
||||||
BOOL ok = ::ReadFile(impl.handle_,
|
BOOL ok = ::ReadFile(impl.handle_, buffer.data(),
|
||||||
asio::buffer_cast<LPVOID>(buffer),
|
static_cast<DWORD>(buffer.size()), 0, &overlapped);
|
||||||
static_cast<DWORD>(asio::buffer_size(buffer)), 0, &overlapped);
|
|
||||||
if (!ok)
|
if (!ok)
|
||||||
{
|
{
|
||||||
DWORD last_error = ::GetLastError();
|
DWORD last_error = ::GetLastError();
|
||||||
@ -469,7 +466,7 @@ void win_iocp_handle_service::start_read_op(
|
|||||||
{
|
{
|
||||||
iocp_service_.on_completion(op, asio::error::bad_descriptor);
|
iocp_service_.on_completion(op, asio::error::bad_descriptor);
|
||||||
}
|
}
|
||||||
else if (asio::buffer_size(buffer) == 0)
|
else if (buffer.size() == 0)
|
||||||
{
|
{
|
||||||
// A request to read 0 bytes on a handle is a no-op.
|
// A request to read 0 bytes on a handle is a no-op.
|
||||||
iocp_service_.on_completion(op);
|
iocp_service_.on_completion(op);
|
||||||
@ -479,9 +476,8 @@ void win_iocp_handle_service::start_read_op(
|
|||||||
DWORD bytes_transferred = 0;
|
DWORD bytes_transferred = 0;
|
||||||
op->Offset = offset & 0xFFFFFFFF;
|
op->Offset = offset & 0xFFFFFFFF;
|
||||||
op->OffsetHigh = (offset >> 32) & 0xFFFFFFFF;
|
op->OffsetHigh = (offset >> 32) & 0xFFFFFFFF;
|
||||||
BOOL ok = ::ReadFile(impl.handle_,
|
BOOL ok = ::ReadFile(impl.handle_, buffer.data(),
|
||||||
asio::buffer_cast<LPVOID>(buffer),
|
static_cast<DWORD>(buffer.size()),
|
||||||
static_cast<DWORD>(asio::buffer_size(buffer)),
|
|
||||||
&bytes_transferred, op);
|
&bytes_transferred, op);
|
||||||
DWORD last_error = ::GetLastError();
|
DWORD last_error = ::GetLastError();
|
||||||
if (!ok && last_error != ERROR_IO_PENDING
|
if (!ok && last_error != ERROR_IO_PENDING
|
||||||
|
@ -344,7 +344,7 @@ namespace detail
|
|||||||
total_transferred_ += bytes_transferred;
|
total_transferred_ += bytes_transferred;
|
||||||
if ((!ec && bytes_transferred == 0)
|
if ((!ec && bytes_transferred == 0)
|
||||||
|| (n = this->check_for_completion(ec, total_transferred_)) == 0
|
|| (n = this->check_for_completion(ec, total_transferred_)) == 0
|
||||||
|| total_transferred_ == asio::buffer_size(buffer_))
|
|| total_transferred_ == buffer_.size())
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,8 +408,8 @@ namespace detail
|
|||||||
boost::array<asio::mutable_buffer, 2> >::type bufs = {{
|
boost::array<asio::mutable_buffer, 2> >::type bufs = {{
|
||||||
asio::mutable_buffer(buffers_[0]),
|
asio::mutable_buffer(buffers_[0]),
|
||||||
asio::mutable_buffer(buffers_[1]) }};
|
asio::mutable_buffer(buffers_[1]) }};
|
||||||
std::size_t buffer_size0 = asio::buffer_size(bufs[0]);
|
std::size_t buffer_size0 = bufs[0].size();
|
||||||
std::size_t buffer_size1 = asio::buffer_size(bufs[1]);
|
std::size_t buffer_size1 = bufs[1].size();
|
||||||
std::size_t n = 0;
|
std::size_t n = 0;
|
||||||
switch (start_ = start)
|
switch (start_ = start)
|
||||||
{
|
{
|
||||||
@ -421,7 +421,7 @@ namespace detail
|
|||||||
bufs[1] = asio::buffer(
|
bufs[1] = asio::buffer(
|
||||||
bufs[1] + (total_transferred_ < buffer_size0
|
bufs[1] + (total_transferred_ < buffer_size0
|
||||||
? 0 : total_transferred_ - buffer_size0),
|
? 0 : total_transferred_ - buffer_size0),
|
||||||
n - asio::buffer_size(bufs[0]));
|
n - bufs[0].size());
|
||||||
stream_.async_read_some(bufs, ASIO_MOVE_CAST(read_op)(*this));
|
stream_.async_read_some(bufs, ASIO_MOVE_CAST(read_op)(*this));
|
||||||
return; default:
|
return; default:
|
||||||
total_transferred_ += bytes_transferred;
|
total_transferred_ += bytes_transferred;
|
||||||
@ -493,8 +493,8 @@ namespace detail
|
|||||||
std::array<asio::mutable_buffer, 2> >::type bufs = {{
|
std::array<asio::mutable_buffer, 2> >::type bufs = {{
|
||||||
asio::mutable_buffer(buffers_[0]),
|
asio::mutable_buffer(buffers_[0]),
|
||||||
asio::mutable_buffer(buffers_[1]) }};
|
asio::mutable_buffer(buffers_[1]) }};
|
||||||
std::size_t buffer_size0 = asio::buffer_size(bufs[0]);
|
std::size_t buffer_size0 = bufs[0].size();
|
||||||
std::size_t buffer_size1 = asio::buffer_size(bufs[1]);
|
std::size_t buffer_size1 = bufs[1].size();
|
||||||
std::size_t n = 0;
|
std::size_t n = 0;
|
||||||
switch (start_ = start)
|
switch (start_ = start)
|
||||||
{
|
{
|
||||||
@ -506,7 +506,7 @@ namespace detail
|
|||||||
bufs[1] = asio::buffer(
|
bufs[1] = asio::buffer(
|
||||||
bufs[1] + (total_transferred_ < buffer_size0
|
bufs[1] + (total_transferred_ < buffer_size0
|
||||||
? 0 : total_transferred_ - buffer_size0),
|
? 0 : total_transferred_ - buffer_size0),
|
||||||
n - asio::buffer_size(bufs[0]));
|
n - bufs[0].size());
|
||||||
stream_.async_read_some(bufs, ASIO_MOVE_CAST(read_op)(*this));
|
stream_.async_read_some(bufs, ASIO_MOVE_CAST(read_op)(*this));
|
||||||
return; default:
|
return; default:
|
||||||
total_transferred_ += bytes_transferred;
|
total_transferred_ += bytes_transferred;
|
||||||
|
@ -295,7 +295,7 @@ namespace detail
|
|||||||
total_transferred_ += bytes_transferred;
|
total_transferred_ += bytes_transferred;
|
||||||
if ((!ec && bytes_transferred == 0)
|
if ((!ec && bytes_transferred == 0)
|
||||||
|| (n = this->check_for_completion(ec, total_transferred_)) == 0
|
|| (n = this->check_for_completion(ec, total_transferred_)) == 0
|
||||||
|| total_transferred_ == asio::buffer_size(buffer_))
|
|| total_transferred_ == buffer_.size())
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -364,8 +364,8 @@ namespace detail
|
|||||||
boost::array<asio::mutable_buffer, 2> >::type bufs = {{
|
boost::array<asio::mutable_buffer, 2> >::type bufs = {{
|
||||||
asio::mutable_buffer(buffers_[0]),
|
asio::mutable_buffer(buffers_[0]),
|
||||||
asio::mutable_buffer(buffers_[1]) }};
|
asio::mutable_buffer(buffers_[1]) }};
|
||||||
std::size_t buffer_size0 = asio::buffer_size(bufs[0]);
|
std::size_t buffer_size0 = bufs[0].size();
|
||||||
std::size_t buffer_size1 = asio::buffer_size(bufs[1]);
|
std::size_t buffer_size1 = bufs[1].size();
|
||||||
std::size_t n = 0;
|
std::size_t n = 0;
|
||||||
switch (start_ = start)
|
switch (start_ = start)
|
||||||
{
|
{
|
||||||
@ -377,7 +377,7 @@ namespace detail
|
|||||||
bufs[1] = asio::buffer(
|
bufs[1] = asio::buffer(
|
||||||
bufs[1] + (total_transferred_ < buffer_size0
|
bufs[1] + (total_transferred_ < buffer_size0
|
||||||
? 0 : total_transferred_ - buffer_size0),
|
? 0 : total_transferred_ - buffer_size0),
|
||||||
n - asio::buffer_size(bufs[0]));
|
n - bufs[0].size());
|
||||||
device_.async_read_some_at(offset_ + total_transferred_,
|
device_.async_read_some_at(offset_ + total_transferred_,
|
||||||
bufs, ASIO_MOVE_CAST(read_at_op)(*this));
|
bufs, ASIO_MOVE_CAST(read_at_op)(*this));
|
||||||
return; default:
|
return; default:
|
||||||
@ -455,8 +455,8 @@ namespace detail
|
|||||||
std::array<asio::mutable_buffer, 2> >::type bufs = {{
|
std::array<asio::mutable_buffer, 2> >::type bufs = {{
|
||||||
asio::mutable_buffer(buffers_[0]),
|
asio::mutable_buffer(buffers_[0]),
|
||||||
asio::mutable_buffer(buffers_[1]) }};
|
asio::mutable_buffer(buffers_[1]) }};
|
||||||
std::size_t buffer_size0 = asio::buffer_size(bufs[0]);
|
std::size_t buffer_size0 = bufs[0].size();
|
||||||
std::size_t buffer_size1 = asio::buffer_size(bufs[1]);
|
std::size_t buffer_size1 = bufs[1].size();
|
||||||
std::size_t n = 0;
|
std::size_t n = 0;
|
||||||
switch (start_ = start)
|
switch (start_ = start)
|
||||||
{
|
{
|
||||||
@ -468,7 +468,7 @@ namespace detail
|
|||||||
bufs[1] = asio::buffer(
|
bufs[1] = asio::buffer(
|
||||||
bufs[1] + (total_transferred_ < buffer_size0
|
bufs[1] + (total_transferred_ < buffer_size0
|
||||||
? 0 : total_transferred_ - buffer_size0),
|
? 0 : total_transferred_ - buffer_size0),
|
||||||
n - asio::buffer_size(bufs[0]));
|
n - bufs[0].size());
|
||||||
device_.async_read_some_at(offset_ + total_transferred_,
|
device_.async_read_some_at(offset_ + total_transferred_,
|
||||||
bufs, ASIO_MOVE_CAST(read_at_op)(*this));
|
bufs, ASIO_MOVE_CAST(read_at_op)(*this));
|
||||||
return; default:
|
return; default:
|
||||||
|
@ -328,7 +328,7 @@ namespace detail
|
|||||||
total_transferred_ += bytes_transferred;
|
total_transferred_ += bytes_transferred;
|
||||||
if ((!ec && bytes_transferred == 0)
|
if ((!ec && bytes_transferred == 0)
|
||||||
|| (n = this->check_for_completion(ec, total_transferred_)) == 0
|
|| (n = this->check_for_completion(ec, total_transferred_)) == 0
|
||||||
|| total_transferred_ == asio::buffer_size(buffer_))
|
|| total_transferred_ == buffer_.size())
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -404,7 +404,7 @@ namespace detail
|
|||||||
total_transferred_ += bytes_transferred;
|
total_transferred_ += bytes_transferred;
|
||||||
if ((!ec && bytes_transferred == 0)
|
if ((!ec && bytes_transferred == 0)
|
||||||
|| (n = this->check_for_completion(ec, total_transferred_)) == 0
|
|| (n = this->check_for_completion(ec, total_transferred_)) == 0
|
||||||
|| total_transferred_ == asio::buffer_size(buffer_))
|
|| total_transferred_ == buffer_.size())
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -468,8 +468,8 @@ namespace detail
|
|||||||
boost::array<asio::const_buffer, 2> >::type bufs = {{
|
boost::array<asio::const_buffer, 2> >::type bufs = {{
|
||||||
asio::const_buffer(buffers_[0]),
|
asio::const_buffer(buffers_[0]),
|
||||||
asio::const_buffer(buffers_[1]) }};
|
asio::const_buffer(buffers_[1]) }};
|
||||||
std::size_t buffer_size0 = asio::buffer_size(bufs[0]);
|
std::size_t buffer_size0 = bufs[0].size();
|
||||||
std::size_t buffer_size1 = asio::buffer_size(bufs[1]);
|
std::size_t buffer_size1 = bufs[1].size();
|
||||||
std::size_t n = 0;
|
std::size_t n = 0;
|
||||||
switch (start_ = start)
|
switch (start_ = start)
|
||||||
{
|
{
|
||||||
@ -481,7 +481,7 @@ namespace detail
|
|||||||
bufs[1] = asio::buffer(
|
bufs[1] = asio::buffer(
|
||||||
bufs[1] + (total_transferred_ < buffer_size0
|
bufs[1] + (total_transferred_ < buffer_size0
|
||||||
? 0 : total_transferred_ - buffer_size0),
|
? 0 : total_transferred_ - buffer_size0),
|
||||||
n - asio::buffer_size(bufs[0]));
|
n - bufs[0].size());
|
||||||
stream_.async_write_some(bufs, ASIO_MOVE_CAST(write_op)(*this));
|
stream_.async_write_some(bufs, ASIO_MOVE_CAST(write_op)(*this));
|
||||||
return; default:
|
return; default:
|
||||||
total_transferred_ += bytes_transferred;
|
total_transferred_ += bytes_transferred;
|
||||||
@ -553,8 +553,8 @@ namespace detail
|
|||||||
std::array<asio::const_buffer, 2> >::type bufs = {{
|
std::array<asio::const_buffer, 2> >::type bufs = {{
|
||||||
asio::const_buffer(buffers_[0]),
|
asio::const_buffer(buffers_[0]),
|
||||||
asio::const_buffer(buffers_[1]) }};
|
asio::const_buffer(buffers_[1]) }};
|
||||||
std::size_t buffer_size0 = asio::buffer_size(bufs[0]);
|
std::size_t buffer_size0 = bufs[0].size();
|
||||||
std::size_t buffer_size1 = asio::buffer_size(bufs[1]);
|
std::size_t buffer_size1 = bufs[1].size();
|
||||||
std::size_t n = 0;
|
std::size_t n = 0;
|
||||||
switch (start_ = start)
|
switch (start_ = start)
|
||||||
{
|
{
|
||||||
@ -566,7 +566,7 @@ namespace detail
|
|||||||
bufs[1] = asio::buffer(
|
bufs[1] = asio::buffer(
|
||||||
bufs[1] + (total_transferred_ < buffer_size0
|
bufs[1] + (total_transferred_ < buffer_size0
|
||||||
? 0 : total_transferred_ - buffer_size0),
|
? 0 : total_transferred_ - buffer_size0),
|
||||||
n - asio::buffer_size(bufs[0]));
|
n - bufs[0].size());
|
||||||
stream_.async_write_some(bufs, ASIO_MOVE_CAST(write_op)(*this));
|
stream_.async_write_some(bufs, ASIO_MOVE_CAST(write_op)(*this));
|
||||||
return; default:
|
return; default:
|
||||||
total_transferred_ += bytes_transferred;
|
total_transferred_ += bytes_transferred;
|
||||||
|
@ -281,7 +281,7 @@ namespace detail
|
|||||||
total_transferred_ += bytes_transferred;
|
total_transferred_ += bytes_transferred;
|
||||||
if ((!ec && bytes_transferred == 0)
|
if ((!ec && bytes_transferred == 0)
|
||||||
|| (n = this->check_for_completion(ec, total_transferred_)) == 0
|
|| (n = this->check_for_completion(ec, total_transferred_)) == 0
|
||||||
|| total_transferred_ == asio::buffer_size(buffer_))
|
|| total_transferred_ == buffer_.size())
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -361,7 +361,7 @@ namespace detail
|
|||||||
total_transferred_ += bytes_transferred;
|
total_transferred_ += bytes_transferred;
|
||||||
if ((!ec && bytes_transferred == 0)
|
if ((!ec && bytes_transferred == 0)
|
||||||
|| (n = this->check_for_completion(ec, total_transferred_)) == 0
|
|| (n = this->check_for_completion(ec, total_transferred_)) == 0
|
||||||
|| total_transferred_ == asio::buffer_size(buffer_))
|
|| total_transferred_ == buffer_.size())
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -430,8 +430,8 @@ namespace detail
|
|||||||
boost::array<asio::const_buffer, 2> >::type bufs = {{
|
boost::array<asio::const_buffer, 2> >::type bufs = {{
|
||||||
asio::const_buffer(buffers_[0]),
|
asio::const_buffer(buffers_[0]),
|
||||||
asio::const_buffer(buffers_[1]) }};
|
asio::const_buffer(buffers_[1]) }};
|
||||||
std::size_t buffer_size0 = asio::buffer_size(bufs[0]);
|
std::size_t buffer_size0 = bufs[0].size();
|
||||||
std::size_t buffer_size1 = asio::buffer_size(bufs[1]);
|
std::size_t buffer_size1 = bufs[1].size();
|
||||||
std::size_t n = 0;
|
std::size_t n = 0;
|
||||||
switch (start_ = start)
|
switch (start_ = start)
|
||||||
{
|
{
|
||||||
@ -443,7 +443,7 @@ namespace detail
|
|||||||
bufs[1] = asio::buffer(
|
bufs[1] = asio::buffer(
|
||||||
bufs[1] + (total_transferred_ < buffer_size0
|
bufs[1] + (total_transferred_ < buffer_size0
|
||||||
? 0 : total_transferred_ - buffer_size0),
|
? 0 : total_transferred_ - buffer_size0),
|
||||||
n - asio::buffer_size(bufs[0]));
|
n - bufs[0].size());
|
||||||
device_.async_write_some_at(offset_ + total_transferred_,
|
device_.async_write_some_at(offset_ + total_transferred_,
|
||||||
bufs, ASIO_MOVE_CAST(write_at_op)(*this));
|
bufs, ASIO_MOVE_CAST(write_at_op)(*this));
|
||||||
return; default:
|
return; default:
|
||||||
@ -521,8 +521,8 @@ namespace detail
|
|||||||
std::array<asio::const_buffer, 2> >::type bufs = {{
|
std::array<asio::const_buffer, 2> >::type bufs = {{
|
||||||
asio::const_buffer(buffers_[0]),
|
asio::const_buffer(buffers_[0]),
|
||||||
asio::const_buffer(buffers_[1]) }};
|
asio::const_buffer(buffers_[1]) }};
|
||||||
std::size_t buffer_size0 = asio::buffer_size(bufs[0]);
|
std::size_t buffer_size0 = bufs[0].size();
|
||||||
std::size_t buffer_size1 = asio::buffer_size(bufs[1]);
|
std::size_t buffer_size1 = bufs[1].size();
|
||||||
std::size_t n = 0;
|
std::size_t n = 0;
|
||||||
switch (start_ = start)
|
switch (start_ = start)
|
||||||
{
|
{
|
||||||
@ -534,7 +534,7 @@ namespace detail
|
|||||||
bufs[1] = asio::buffer(
|
bufs[1] = asio::buffer(
|
||||||
bufs[1] + (total_transferred_ < buffer_size0
|
bufs[1] + (total_transferred_ < buffer_size0
|
||||||
? 0 : total_transferred_ - buffer_size0),
|
? 0 : total_transferred_ - buffer_size0),
|
||||||
n - asio::buffer_size(bufs[0]));
|
n - bufs[0].size());
|
||||||
device_.async_write_some_at(offset_ + total_transferred_,
|
device_.async_write_some_at(offset_ + total_transferred_,
|
||||||
bufs, ASIO_MOVE_CAST(write_at_op)(*this));
|
bufs, ASIO_MOVE_CAST(write_at_op)(*this));
|
||||||
return; default:
|
return; default:
|
||||||
|
@ -58,9 +58,9 @@ public:
|
|||||||
const_buffer buffer(*iter);
|
const_buffer buffer(*iter);
|
||||||
|
|
||||||
// Skip over any buffers which have already been consumed by the engine.
|
// Skip over any buffers which have already been consumed by the engine.
|
||||||
if (bytes_transferred >= accumulated_size + buffer_size(buffer))
|
if (bytes_transferred >= accumulated_size + buffer.size())
|
||||||
{
|
{
|
||||||
accumulated_size += buffer_size(buffer);
|
accumulated_size += buffer.size();
|
||||||
++iter;
|
++iter;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -73,9 +73,9 @@ public:
|
|||||||
|
|
||||||
// Pass the buffer to the engine, and update the bytes transferred to
|
// Pass the buffer to the engine, and update the bytes transferred to
|
||||||
// reflect the total number of bytes consumed so far.
|
// reflect the total number of bytes consumed so far.
|
||||||
bytes_transferred += buffer_size(buffer);
|
bytes_transferred += buffer.size();
|
||||||
buffer = eng.put_input(buffer);
|
buffer = eng.put_input(buffer);
|
||||||
bytes_transferred -= buffer_size(buffer);
|
bytes_transferred -= buffer.size();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,37 +141,35 @@ engine::want engine::shutdown(asio::error_code& ec)
|
|||||||
engine::want engine::write(const asio::const_buffer& data,
|
engine::want engine::write(const asio::const_buffer& data,
|
||||||
asio::error_code& ec, std::size_t& bytes_transferred)
|
asio::error_code& ec, std::size_t& bytes_transferred)
|
||||||
{
|
{
|
||||||
if (asio::buffer_size(data) == 0)
|
if (data.size() == 0)
|
||||||
{
|
{
|
||||||
ec = asio::error_code();
|
ec = asio::error_code();
|
||||||
return engine::want_nothing;
|
return engine::want_nothing;
|
||||||
}
|
}
|
||||||
|
|
||||||
return perform(&engine::do_write,
|
return perform(&engine::do_write,
|
||||||
const_cast<void*>(asio::buffer_cast<const void*>(data)),
|
const_cast<void*>(data.data()),
|
||||||
asio::buffer_size(data), ec, &bytes_transferred);
|
data.size(), ec, &bytes_transferred);
|
||||||
}
|
}
|
||||||
|
|
||||||
engine::want engine::read(const asio::mutable_buffer& data,
|
engine::want engine::read(const asio::mutable_buffer& data,
|
||||||
asio::error_code& ec, std::size_t& bytes_transferred)
|
asio::error_code& ec, std::size_t& bytes_transferred)
|
||||||
{
|
{
|
||||||
if (asio::buffer_size(data) == 0)
|
if (data.size() == 0)
|
||||||
{
|
{
|
||||||
ec = asio::error_code();
|
ec = asio::error_code();
|
||||||
return engine::want_nothing;
|
return engine::want_nothing;
|
||||||
}
|
}
|
||||||
|
|
||||||
return perform(&engine::do_read,
|
return perform(&engine::do_read, data.data(),
|
||||||
asio::buffer_cast<void*>(data),
|
data.size(), ec, &bytes_transferred);
|
||||||
asio::buffer_size(data), ec, &bytes_transferred);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
asio::mutable_buffers_1 engine::get_output(
|
asio::mutable_buffers_1 engine::get_output(
|
||||||
const asio::mutable_buffer& data)
|
const asio::mutable_buffer& data)
|
||||||
{
|
{
|
||||||
int length = ::BIO_read(ext_bio_,
|
int length = ::BIO_read(ext_bio_,
|
||||||
asio::buffer_cast<void*>(data),
|
data.data(), static_cast<int>(data.size()));
|
||||||
static_cast<int>(asio::buffer_size(data)));
|
|
||||||
|
|
||||||
return asio::buffer(data,
|
return asio::buffer(data,
|
||||||
length > 0 ? static_cast<std::size_t>(length) : 0);
|
length > 0 ? static_cast<std::size_t>(length) : 0);
|
||||||
@ -181,8 +179,7 @@ asio::const_buffer engine::put_input(
|
|||||||
const asio::const_buffer& data)
|
const asio::const_buffer& data)
|
||||||
{
|
{
|
||||||
int length = ::BIO_write(ext_bio_,
|
int length = ::BIO_write(ext_bio_,
|
||||||
asio::buffer_cast<const void*>(data),
|
data.data(), static_cast<int>(data.size()));
|
||||||
static_cast<int>(asio::buffer_size(data)));
|
|
||||||
|
|
||||||
return asio::buffer(data +
|
return asio::buffer(data +
|
||||||
(length > 0 ? static_cast<std::size_t>(length) : 0));
|
(length > 0 ? static_cast<std::size_t>(length) : 0));
|
||||||
|
@ -38,7 +38,7 @@ std::size_t io(Stream& next_layer, stream_core& core,
|
|||||||
|
|
||||||
// If the input buffer is empty then we need to read some more data from
|
// If the input buffer is empty then we need to read some more data from
|
||||||
// the underlying transport.
|
// the underlying transport.
|
||||||
if (asio::buffer_size(core.input_) == 0)
|
if (core.input_.size() == 0)
|
||||||
core.input_ = asio::buffer(core.input_buffer_,
|
core.input_ = asio::buffer(core.input_buffer_,
|
||||||
next_layer.read_some(core.input_buffer_, ec));
|
next_layer.read_some(core.input_buffer_, ec));
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ public:
|
|||||||
|
|
||||||
// If the input buffer already has data in it we can pass it to the
|
// If the input buffer already has data in it we can pass it to the
|
||||||
// engine and then retry the operation immediately.
|
// engine and then retry the operation immediately.
|
||||||
if (asio::buffer_size(core_.input_) != 0)
|
if (core_.input_.size() != 0)
|
||||||
{
|
{
|
||||||
core_.input_ = core_.engine_.put_input(core_.input_);
|
core_.input_ = core_.engine_.put_input(core_.input_);
|
||||||
continue;
|
continue;
|
||||||
|
@ -427,8 +427,8 @@ asio::error_code context::use_certificate(
|
|||||||
if (format == context_base::asn1)
|
if (format == context_base::asn1)
|
||||||
{
|
{
|
||||||
if (::SSL_CTX_use_certificate_ASN1(handle_,
|
if (::SSL_CTX_use_certificate_ASN1(handle_,
|
||||||
static_cast<int>(buffer_size(certificate)),
|
static_cast<int>(certificate.size()),
|
||||||
buffer_cast<const unsigned char*>(certificate)) == 1)
|
static_cast<const unsigned char*>(certificate.data())) == 1)
|
||||||
{
|
{
|
||||||
ec = asio::error_code();
|
ec = asio::error_code();
|
||||||
return ec;
|
return ec;
|
||||||
@ -943,8 +943,8 @@ int context::password_callback_function(
|
|||||||
BIO* context::make_buffer_bio(const const_buffer& b)
|
BIO* context::make_buffer_bio(const const_buffer& b)
|
||||||
{
|
{
|
||||||
return ::BIO_new_mem_buf(
|
return ::BIO_new_mem_buf(
|
||||||
const_cast<void*>(buffer_cast<const void*>(b)),
|
const_cast<void*>(b.data()),
|
||||||
static_cast<int>(buffer_size(b)));
|
static_cast<int>(b.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ssl
|
} // namespace ssl
|
||||||
|
@ -45,7 +45,7 @@ an opaque representation of contiguous memory, where:
|
|||||||
mechanisms for automatically determining the size of a buffer from an array,
|
mechanisms for automatically determining the size of a buffer from an array,
|
||||||
`boost::array` or `std::vector` of POD elements, or from a `std::string`.
|
`boost::array` or `std::vector` of POD elements, or from a `std::string`.
|
||||||
|
|
||||||
* Type safety violations must be explicitly requested using the `buffer_cast`
|
* The underlying memory is explicitly accessed using the `data()` member
|
||||||
function. In general an application should never need to do this, but it is
|
function. In general an application should never need to do this, but it is
|
||||||
required by the library implementation to pass the raw memory to the
|
required by the library implementation to pass the raw memory to the
|
||||||
underlying operating system functions.
|
underlying operating system functions.
|
||||||
|
@ -68,6 +68,14 @@ void test()
|
|||||||
mutable_buffer mb2(void_ptr_data, 1024);
|
mutable_buffer mb2(void_ptr_data, 1024);
|
||||||
mutable_buffer mb3(mb1);
|
mutable_buffer mb3(mb1);
|
||||||
|
|
||||||
|
// mutable_buffer functions.
|
||||||
|
|
||||||
|
void* ptr1 = mb1.data();
|
||||||
|
(void)ptr1;
|
||||||
|
|
||||||
|
std::size_t n1 = mb1.size();
|
||||||
|
(void)n1;
|
||||||
|
|
||||||
// mutable_buffer operators.
|
// mutable_buffer operators.
|
||||||
|
|
||||||
mb1 = mb2 + 128;
|
mb1 = mb2 + 128;
|
||||||
@ -92,6 +100,14 @@ void test()
|
|||||||
const_buffer cb3(cb1);
|
const_buffer cb3(cb1);
|
||||||
const_buffer cb4(mb1);
|
const_buffer cb4(mb1);
|
||||||
|
|
||||||
|
// const_buffer functions.
|
||||||
|
|
||||||
|
const void* ptr2 = cb1.data();
|
||||||
|
(void)ptr2;
|
||||||
|
|
||||||
|
std::size_t n2 = cb1.size();
|
||||||
|
(void)n2;
|
||||||
|
|
||||||
// const_buffer operators.
|
// const_buffer operators.
|
||||||
|
|
||||||
cb1 = cb2 + 128;
|
cb1 = cb2 + 128;
|
||||||
@ -126,10 +142,12 @@ void test()
|
|||||||
|
|
||||||
// buffer_cast function overloads.
|
// buffer_cast function overloads.
|
||||||
|
|
||||||
void* ptr1 = buffer_cast<void*>(mb1);
|
#if !defined(ASIO_NO_DEPRECATED)
|
||||||
(void)ptr1;
|
void* ptr3 = buffer_cast<void*>(mb1);
|
||||||
const void* ptr2 = buffer_cast<const void*>(cb1);
|
(void)ptr3;
|
||||||
(void)ptr2;
|
const void* ptr4 = buffer_cast<const void*>(cb1);
|
||||||
|
(void)ptr4;
|
||||||
|
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||||
|
|
||||||
// buffer function overloads.
|
// buffer function overloads.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user