|
Boost-Commit : |
From: chris_at_[hidden]
Date: 2008-08-28 08:11:49
Author: chris_kohlhoff
Date: 2008-08-28 08:11:47 EDT (Thu, 28 Aug 2008)
New Revision: 48418
URL: http://svn.boost.org/trac/boost/changeset/48418
Log:
Change the CompletionCondition concept so that:
- It is now evaluated before the first call to the underlying
*_some() operation, as well as after every operation.
- The return value is a number of bytes, which indicates the maximum
length to be transferred on the subsequent *_some() operation. If
the return value is 0 then the composed operation completes.
Add missing unit tests for read_at and write_at.
Added:
trunk/libs/asio/test/read_at.cpp (contents, props changed)
trunk/libs/asio/test/write_at.cpp (contents, props changed)
Text files modified:
trunk/boost/asio/completion_condition.hpp | 31 +++++-
trunk/boost/asio/detail/consuming_buffers.hpp | 39 ++++++--
trunk/boost/asio/impl/read.ipp | 67 ++++++++++---
trunk/boost/asio/impl/read_at.ipp | 50 ++++++++--
trunk/boost/asio/impl/write.ipp | 25 ++++-
trunk/boost/asio/impl/write_at.ipp | 25 ++++-
trunk/libs/asio/test/Jamfile | 2
trunk/libs/asio/test/Jamfile.v2 | 4
trunk/libs/asio/test/read.cpp | 189 +++++++++++++++++++++++++++++++++++++++
trunk/libs/asio/test/write.cpp | 171 +++++++++++++++++++++++++++++++++++
10 files changed, 547 insertions(+), 56 deletions(-)
Modified: trunk/boost/asio/completion_condition.hpp
==============================================================================
--- trunk/boost/asio/completion_condition.hpp (original)
+++ trunk/boost/asio/completion_condition.hpp 2008-08-28 08:11:47 EDT (Thu, 28 Aug 2008)
@@ -27,22 +27,40 @@
namespace detail {
+// The default maximum number of bytes to transfer in a single operation.
+enum { default_max_transfer_size = 65536 };
+
+// Adapt result of old-style completion conditions (which had a bool result
+// where true indicated that the operation was complete).
+inline std::size_t adapt_completion_condition_result(bool result)
+{
+ return result ? 0 : default_max_transfer_size;
+}
+
+// Adapt result of current completion conditions (which have a size_t result
+// where 0 means the operation is complete, and otherwise the result is the
+// maximum number of bytes to transfer on the next underlying operation).
+inline std::size_t adapt_completion_condition_result(std::size_t result)
+{
+ return result;
+}
+
class transfer_all_t
{
public:
- typedef bool result_type;
+ typedef std::size_t result_type;
template <typename Error>
- bool operator()(const Error& err, std::size_t)
+ std::size_t operator()(const Error& err, std::size_t)
{
- return !!err;
+ return !!err ? 0 : default_max_transfer_size;
}
};
class transfer_at_least_t
{
public:
- typedef bool result_type;
+ typedef std::size_t result_type;
explicit transfer_at_least_t(std::size_t minimum)
: minimum_(minimum)
@@ -50,9 +68,10 @@
}
template <typename Error>
- bool operator()(const Error& err, std::size_t bytes_transferred)
+ std::size_t operator()(const Error& err, std::size_t bytes_transferred)
{
- return !!err || bytes_transferred >= minimum_;
+ return (!!err || bytes_transferred >= minimum_)
+ ? 0 : default_max_transfer_size;
}
private:
Modified: trunk/boost/asio/detail/consuming_buffers.hpp
==============================================================================
--- trunk/boost/asio/detail/consuming_buffers.hpp (original)
+++ trunk/boost/asio/detail/consuming_buffers.hpp 2008-08-28 08:11:47 EDT (Thu, 28 Aug 2008)
@@ -20,11 +20,13 @@
#include <boost/asio/detail/push_options.hpp>
#include <algorithm>
#include <cstddef>
+#include <limits>
#include <boost/config.hpp>
#include <boost/iterator/iterator_facade.hpp>
#include <boost/asio/detail/pop_options.hpp>
#include <boost/asio/buffer.hpp>
+#include <boost/asio/completion_condition.hpp>
namespace boost {
namespace asio {
@@ -47,33 +49,33 @@
// Construct with a buffer for the first entry and an iterator
// range for the remaining entries.
consuming_buffers_iterator(bool at_end, const Buffer& first,
- Buffer_Iterator begin_remainder, Buffer_Iterator end_remainder)
- : at_end_(at_end),
+ Buffer_Iterator begin_remainder, Buffer_Iterator end_remainder,
+ std::size_t max_size)
+ : at_end_(max_size > 0 ? at_end : true),
first_(buffer(first, max_size)),
begin_remainder_(begin_remainder),
end_remainder_(end_remainder),
- offset_(0)
+ offset_(0),
+ max_size_(max_size)
{
}
private:
friend class boost::iterator_core_access;
- enum { max_size = 65536 };
-
void increment()
{
if (!at_end_)
{
if (begin_remainder_ == end_remainder_
- || offset_ + buffer_size(first_) >= max_size)
+ || offset_ + buffer_size(first_) >= max_size_)
{
at_end_ = true;
}
else
{
offset_ += buffer_size(first_);
- first_ = buffer(*begin_remainder_++, max_size - offset_);
+ first_ = buffer(*begin_remainder_++, max_size_ - offset_);
}
}
}
@@ -100,6 +102,7 @@
Buffer_Iterator begin_remainder_;
Buffer_Iterator end_remainder_;
std::size_t offset_;
+ std::size_t max_size_;
};
// A proxy for a sub-range in a list of buffers.
@@ -119,7 +122,8 @@
: buffers_(buffers),
at_end_(buffers_.begin() == buffers_.end()),
first_(*buffers_.begin()),
- begin_remainder_(buffers_.begin())
+ begin_remainder_(buffers_.begin()),
+ max_size_((std::numeric_limits<std::size_t>::max)())
{
if (!at_end_)
++begin_remainder_;
@@ -130,7 +134,8 @@
: buffers_(other.buffers_),
at_end_(other.at_end_),
first_(other.first_),
- begin_remainder_(buffers_.begin())
+ begin_remainder_(buffers_.begin()),
+ max_size_(other.max_size_)
{
typename Buffers::const_iterator first = other.buffers_.begin();
typename Buffers::const_iterator second = other.begin_remainder_;
@@ -147,13 +152,15 @@
typename Buffers::const_iterator first = other.buffers_.begin();
typename Buffers::const_iterator second = other.begin_remainder_;
std::advance(begin_remainder_, std::distance(first, second));
+ max_size_ = other.max_size_;
return *this;
}
// Get a forward-only iterator to the first element.
const_iterator begin() const
{
- return const_iterator(at_end_, first_, begin_remainder_, buffers_.end());
+ return const_iterator(at_end_, first_,
+ begin_remainder_, buffers_.end(), max_size_);
}
// Get a forward-only iterator for one past the last element.
@@ -162,6 +169,12 @@
return const_iterator();
}
+ // Set the maximum size for a single transfer.
+ void set_max_size(std::size_t max_size)
+ {
+ max_size_ = max_size;
+ }
+
// Consume the specified number of bytes from the buffers.
void consume(std::size_t size)
{
@@ -198,6 +211,7 @@
bool at_end_;
Buffer first_;
typename Buffers::const_iterator begin_remainder_;
+ std::size_t max_size_;
};
// Specialisation for null_buffers to ensure that the null_buffers type is
@@ -212,6 +226,11 @@
// No-op.
}
+ void set_max_size(std::size_t)
+ {
+ // No-op.
+ }
+
void consume(std::size_t)
{
// No-op.
Modified: trunk/boost/asio/impl/read.ipp
==============================================================================
--- trunk/boost/asio/impl/read.ipp (original)
+++ trunk/boost/asio/impl/read.ipp 2008-08-28 08:11:47 EDT (Thu, 28 Aug 2008)
@@ -38,18 +38,20 @@
std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
CompletionCondition completion_condition, boost::system::error_code& ec)
{
+ ec = boost::system::error_code();
boost::asio::detail::consuming_buffers<
mutable_buffer, MutableBufferSequence> tmp(buffers);
std::size_t total_transferred = 0;
+ tmp.set_max_size(detail::adapt_completion_condition_result(
+ completion_condition(ec, total_transferred)));
while (tmp.begin() != tmp.end())
{
std::size_t bytes_transferred = s.read_some(tmp, ec);
tmp.consume(bytes_transferred);
total_transferred += bytes_transferred;
- if (completion_condition(ec, total_transferred))
- return total_transferred;
+ tmp.set_max_size(detail::adapt_completion_condition_result(
+ completion_condition(ec, total_transferred)));
}
- ec = boost::system::error_code();
return total_transferred;
}
@@ -79,18 +81,23 @@
boost::asio::basic_streambuf<Allocator>& b,
CompletionCondition completion_condition, boost::system::error_code& ec)
{
+ ec = boost::system::error_code();
std::size_t total_transferred = 0;
- for (;;)
+ std::size_t max_size = detail::adapt_completion_condition_result(
+ completion_condition(ec, total_transferred));
+ std::size_t bytes_available = std::min<std::size_t>(512,
+ std::min<std::size_t>(max_size, b.max_size() - b.size()));
+ while (bytes_available > 0)
{
- std::size_t bytes_available =
- std::min<std::size_t>(512, b.max_size() - b.size());
std::size_t bytes_transferred = s.read_some(b.prepare(bytes_available), ec);
b.commit(bytes_transferred);
total_transferred += bytes_transferred;
- if (b.size() == b.max_size()
- || completion_condition(ec, total_transferred))
- return total_transferred;
+ max_size = detail::adapt_completion_condition_result(
+ completion_condition(ec, total_transferred));
+ bytes_available = std::min<std::size_t>(512,
+ std::min<std::size_t>(max_size, b.max_size() - b.size()));
}
+ return total_transferred;
}
template <typename SyncReadStream, typename Allocator>
@@ -140,8 +147,9 @@
{
total_transferred_ += bytes_transferred;
buffers_.consume(bytes_transferred);
- if (completion_condition_(ec, total_transferred_)
- || buffers_.begin() == buffers_.end())
+ buffers_.set_max_size(detail::adapt_completion_condition_result(
+ completion_condition_(ec, total_transferred_)));
+ if (buffers_.begin() == buffers_.end())
{
handler_(ec, total_transferred_);
}
@@ -198,6 +206,18 @@
{
boost::asio::detail::consuming_buffers<
mutable_buffer, MutableBufferSequence> tmp(buffers);
+
+ boost::system::error_code ec;
+ std::size_t total_transferred = 0;
+ tmp.set_max_size(detail::adapt_completion_condition_result(
+ completion_condition(ec, total_transferred)));
+ if (tmp.begin() == tmp.end())
+ {
+ s.get_io_service().post(detail::bind_handler(
+ handler, ec, total_transferred));
+ return;
+ }
+
s.async_read_some(tmp,
detail::read_handler<AsyncReadStream, MutableBufferSequence,
CompletionCondition, ReadHandler>(
@@ -235,15 +255,17 @@
{
total_transferred_ += bytes_transferred;
streambuf_.commit(bytes_transferred);
- if (streambuf_.size() == streambuf_.max_size()
- || completion_condition_(ec, total_transferred_))
+ std::size_t max_size = detail::adapt_completion_condition_result(
+ completion_condition_(ec, total_transferred_));
+ std::size_t bytes_available = std::min<std::size_t>(512,
+ std::min<std::size_t>(max_size,
+ streambuf_.max_size() - streambuf_.size()));
+ if (bytes_available == 0)
{
handler_(ec, total_transferred_);
}
else
{
- std::size_t bytes_available =
- std::min<std::size_t>(512, streambuf_.max_size() - streambuf_.size());
stream_.async_read_some(streambuf_.prepare(bytes_available), *this);
}
}
@@ -293,8 +315,19 @@
boost::asio::basic_streambuf<Allocator>& b,
CompletionCondition completion_condition, ReadHandler handler)
{
- std::size_t bytes_available =
- std::min<std::size_t>(512, b.max_size() - b.size());
+ boost::system::error_code ec;
+ std::size_t total_transferred = 0;
+ std::size_t max_size = detail::adapt_completion_condition_result(
+ completion_condition(ec, total_transferred));
+ std::size_t bytes_available = std::min<std::size_t>(512,
+ std::min<std::size_t>(max_size, b.max_size() - b.size()));
+ if (bytes_available == 0)
+ {
+ s.get_io_service().post(detail::bind_handler(
+ handler, ec, total_transferred));
+ return;
+ }
+
s.async_read_some(b.prepare(bytes_available),
detail::read_streambuf_handler<AsyncReadStream, Allocator,
CompletionCondition, ReadHandler>(
Modified: trunk/boost/asio/impl/read_at.ipp
==============================================================================
--- trunk/boost/asio/impl/read_at.ipp (original)
+++ trunk/boost/asio/impl/read_at.ipp 2008-08-28 08:11:47 EDT (Thu, 28 Aug 2008)
@@ -39,19 +39,21 @@
boost::uint64_t offset, const MutableBufferSequence& buffers,
CompletionCondition completion_condition, boost::system::error_code& ec)
{
+ ec = boost::system::error_code();
boost::asio::detail::consuming_buffers<
mutable_buffer, MutableBufferSequence> tmp(buffers);
std::size_t total_transferred = 0;
+ tmp.set_max_size(detail::adapt_completion_condition_result(
+ completion_condition(ec, total_transferred)));
while (tmp.begin() != tmp.end())
{
std::size_t bytes_transferred = d.read_some_at(
offset + total_transferred, tmp, ec);
tmp.consume(bytes_transferred);
total_transferred += bytes_transferred;
- if (completion_condition(ec, total_transferred))
- return total_transferred;
+ tmp.set_max_size(detail::adapt_completion_condition_result(
+ completion_condition(ec, total_transferred)));
}
- ec = boost::system::error_code();
return total_transferred;
}
@@ -152,8 +154,9 @@
{
total_transferred_ += bytes_transferred;
buffers_.consume(bytes_transferred);
- if (completion_condition_(ec, total_transferred_)
- || buffers_.begin() == buffers_.end())
+ buffers_.set_max_size(detail::adapt_completion_condition_result(
+ completion_condition_(ec, total_transferred_)));
+ if (buffers_.begin() == buffers_.end())
{
handler_(ec, total_transferred_);
}
@@ -215,6 +218,18 @@
{
boost::asio::detail::consuming_buffers<
mutable_buffer, MutableBufferSequence> tmp(buffers);
+
+ boost::system::error_code ec;
+ std::size_t total_transferred = 0;
+ tmp.set_max_size(detail::adapt_completion_condition_result(
+ completion_condition(ec, total_transferred)));
+ if (tmp.begin() == tmp.end())
+ {
+ d.get_io_service().post(detail::bind_handler(
+ handler, ec, total_transferred));
+ return;
+ }
+
d.async_read_some_at(offset, tmp,
detail::read_at_handler<AsyncRandomAccessReadDevice,
MutableBufferSequence, CompletionCondition, ReadHandler>(
@@ -254,15 +269,17 @@
{
total_transferred_ += bytes_transferred;
streambuf_.commit(bytes_transferred);
- if (streambuf_.size() == streambuf_.max_size()
- || completion_condition_(ec, total_transferred_))
+ std::size_t max_size = detail::adapt_completion_condition_result(
+ completion_condition_(ec, total_transferred_));
+ std::size_t bytes_available = std::min<std::size_t>(512,
+ std::min<std::size_t>(max_size,
+ streambuf_.max_size() - streambuf_.size()));
+ if (bytes_available == 0)
{
handler_(ec, total_transferred_);
}
else
{
- std::size_t bytes_available =
- std::min<std::size_t>(512, streambuf_.max_size() - streambuf_.size());
stream_.async_read_some_at(offset_ + total_transferred_,
streambuf_.prepare(bytes_available), *this);
}
@@ -314,8 +331,19 @@
boost::uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
CompletionCondition completion_condition, ReadHandler handler)
{
- std::size_t bytes_available =
- std::min<std::size_t>(512, b.max_size() - b.size());
+ boost::system::error_code ec;
+ std::size_t total_transferred = 0;
+ std::size_t max_size = detail::adapt_completion_condition_result(
+ completion_condition(ec, total_transferred));
+ std::size_t bytes_available = std::min<std::size_t>(512,
+ std::min<std::size_t>(max_size, b.max_size() - b.size()));
+ if (bytes_available == 0)
+ {
+ d.get_io_service().post(detail::bind_handler(
+ handler, ec, total_transferred));
+ return;
+ }
+
d.async_read_some_at(offset, b.prepare(bytes_available),
detail::read_at_streambuf_handler<AsyncRandomAccessReadDevice, Allocator,
CompletionCondition, ReadHandler>(
Modified: trunk/boost/asio/impl/write.ipp
==============================================================================
--- trunk/boost/asio/impl/write.ipp (original)
+++ trunk/boost/asio/impl/write.ipp 2008-08-28 08:11:47 EDT (Thu, 28 Aug 2008)
@@ -33,18 +33,20 @@
std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
CompletionCondition completion_condition, boost::system::error_code& ec)
{
+ ec = boost::system::error_code();
boost::asio::detail::consuming_buffers<
const_buffer, ConstBufferSequence> tmp(buffers);
std::size_t total_transferred = 0;
+ tmp.set_max_size(detail::adapt_completion_condition_result(
+ completion_condition(ec, total_transferred)));
while (tmp.begin() != tmp.end())
{
std::size_t bytes_transferred = s.write_some(tmp, ec);
tmp.consume(bytes_transferred);
total_transferred += bytes_transferred;
- if (completion_condition(ec, total_transferred))
- return total_transferred;
+ tmp.set_max_size(detail::adapt_completion_condition_result(
+ completion_condition(ec, total_transferred)));
}
- ec = boost::system::error_code();
return total_transferred;
}
@@ -126,8 +128,9 @@
{
total_transferred_ += bytes_transferred;
buffers_.consume(bytes_transferred);
- if (completion_condition_(ec, total_transferred_)
- || buffers_.begin() == buffers_.end())
+ buffers_.set_max_size(detail::adapt_completion_condition_result(
+ completion_condition_(ec, total_transferred_)));
+ if (buffers_.begin() == buffers_.end())
{
handler_(ec, total_transferred_);
}
@@ -184,6 +187,18 @@
{
boost::asio::detail::consuming_buffers<
const_buffer, ConstBufferSequence> tmp(buffers);
+
+ boost::system::error_code ec;
+ std::size_t total_transferred = 0;
+ tmp.set_max_size(detail::adapt_completion_condition_result(
+ completion_condition(ec, total_transferred)));
+ if (tmp.begin() == tmp.end())
+ {
+ s.get_io_service().post(detail::bind_handler(
+ handler, ec, total_transferred));
+ return;
+ }
+
s.async_write_some(tmp,
detail::write_handler<AsyncWriteStream, ConstBufferSequence,
CompletionCondition, WriteHandler>(
Modified: trunk/boost/asio/impl/write_at.ipp
==============================================================================
--- trunk/boost/asio/impl/write_at.ipp (original)
+++ trunk/boost/asio/impl/write_at.ipp 2008-08-28 08:11:47 EDT (Thu, 28 Aug 2008)
@@ -34,19 +34,21 @@
boost::uint64_t offset, const ConstBufferSequence& buffers,
CompletionCondition completion_condition, boost::system::error_code& ec)
{
+ ec = boost::system::error_code();
boost::asio::detail::consuming_buffers<
const_buffer, ConstBufferSequence> tmp(buffers);
std::size_t total_transferred = 0;
+ tmp.set_max_size(detail::adapt_completion_condition_result(
+ completion_condition(ec, total_transferred)));
while (tmp.begin() != tmp.end())
{
std::size_t bytes_transferred = d.write_some_at(
offset + total_transferred, tmp, ec);
tmp.consume(bytes_transferred);
total_transferred += bytes_transferred;
- if (completion_condition(ec, total_transferred))
- return total_transferred;
+ tmp.set_max_size(detail::adapt_completion_condition_result(
+ completion_condition(ec, total_transferred)));
}
- ec = boost::system::error_code();
return total_transferred;
}
@@ -136,8 +138,9 @@
{
total_transferred_ += bytes_transferred;
buffers_.consume(bytes_transferred);
- if (completion_condition_(ec, total_transferred_)
- || buffers_.begin() == buffers_.end())
+ buffers_.set_max_size(detail::adapt_completion_condition_result(
+ completion_condition_(ec, total_transferred_)));
+ if (buffers_.begin() == buffers_.end())
{
handler_(ec, total_transferred_);
}
@@ -197,6 +200,18 @@
{
boost::asio::detail::consuming_buffers<
const_buffer, ConstBufferSequence> tmp(buffers);
+
+ boost::system::error_code ec;
+ std::size_t total_transferred = 0;
+ tmp.set_max_size(detail::adapt_completion_condition_result(
+ completion_condition(ec, total_transferred)));
+ if (tmp.begin() == tmp.end())
+ {
+ d.get_io_service().post(detail::bind_handler(
+ handler, ec, total_transferred));
+ return;
+ }
+
d.async_write_some_at(offset, tmp,
detail::write_at_handler<AsyncRandomAccessWriteDevice,
ConstBufferSequence, CompletionCondition, WriteHandler>(
Modified: trunk/libs/asio/test/Jamfile
==============================================================================
--- trunk/libs/asio/test/Jamfile (original)
+++ trunk/libs/asio/test/Jamfile 2008-08-28 08:11:47 EDT (Thu, 28 Aug 2008)
@@ -81,6 +81,7 @@
[ run posix/stream_descriptor.cpp <template>asio_unit_test ]
[ run posix/stream_descriptor_service.cpp <template>asio_unit_test ]
[ run read.cpp <template>asio_unit_test ]
+ [ run read_at.cpp <template>asio_unit_test ]
[ run read_until.cpp <template>asio_unit_test ]
[ run socket_acceptor_service.cpp <template>asio_unit_test ]
[ run socket_base.cpp <template>asio_unit_test ]
@@ -95,4 +96,5 @@
[ run windows/stream_handle.cpp <template>asio_unit_test ]
[ run windows/stream_handle_service.cpp <template>asio_unit_test ]
[ run write.cpp <template>asio_unit_test ]
+ [ run write_at.cpp <template>asio_unit_test ]
;
Modified: trunk/libs/asio/test/Jamfile.v2
==============================================================================
--- trunk/libs/asio/test/Jamfile.v2 (original)
+++ trunk/libs/asio/test/Jamfile.v2 2008-08-28 08:11:47 EDT (Thu, 28 Aug 2008)
@@ -142,6 +142,8 @@
[ link posix/stream_descriptor_service.cpp : $(USE_SELECT) : posix_stream_descriptor_service_select ]
[ run read.cpp ]
[ run read.cpp : : : $(USE_SELECT) : read_select ]
+ [ run read_at.cpp ]
+ [ run read_at.cpp : : : $(USE_SELECT) : read_at_select ]
[ run read_until.cpp ]
[ run read_until.cpp : : : $(USE_SELECT) : read_until_select ]
[ link socket_acceptor_service.cpp ]
@@ -170,4 +172,6 @@
[ link windows/stream_handle_service.cpp : $(USE_SELECT) : windows_stream_handle_service_select ]
[ run write.cpp ]
[ run write.cpp : : : $(USE_SELECT) : write_select ]
+ [ run write_at.cpp ]
+ [ run write_at.cpp : : : $(USE_SELECT) : write_at_select ]
;
Modified: trunk/libs/asio/test/read.cpp
==============================================================================
--- trunk/libs/asio/test/read.cpp (original)
+++ trunk/libs/asio/test/read.cpp 2008-08-28 08:11:47 EDT (Thu, 28 Aug 2008)
@@ -38,7 +38,7 @@
{
}
- io_service_type& io_service()
+ io_service_type& get_io_service()
{
return io_service_;
}
@@ -162,6 +162,18 @@
BOOST_CHECK(s.check(buffers, sizeof(read_data)));
}
+bool old_style_transfer_all(const boost::system::error_code& ec,
+ size_t bytes_transferred)
+{
+ return !!ec;
+}
+
+size_t short_transfer(const boost::system::error_code& ec,
+ size_t bytes_transferred)
+{
+ return !!ec ? 0 : 3;
+}
+
void test_3_arg_read()
{
boost::asio::io_service ios;
@@ -261,6 +273,46 @@
boost::asio::transfer_at_least(42));
BOOST_CHECK(bytes_transferred == 50);
BOOST_CHECK(s.check(buffers, 50));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read(s, buffers, old_style_transfer_all);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read(s, buffers, old_style_transfer_all);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read(s, buffers, old_style_transfer_all);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read(s, buffers, short_transfer);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read(s, buffers, short_transfer);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read(s, buffers, short_transfer);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(buffers, sizeof(read_data)));
}
void test_4_arg_read()
@@ -386,6 +438,59 @@
BOOST_CHECK(bytes_transferred == 50);
BOOST_CHECK(s.check(buffers, 50));
BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read(s, buffers,
+ old_style_transfer_all, error);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(buffers, sizeof(read_data)));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read(s, buffers,
+ old_style_transfer_all, error);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(buffers, sizeof(read_data)));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read(s, buffers,
+ old_style_transfer_all, error);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(buffers, sizeof(read_data)));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read(s, buffers, short_transfer, error);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(buffers, sizeof(read_data)));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read(s, buffers, short_transfer, error);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(buffers, sizeof(read_data)));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read(s, buffers, short_transfer, error);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(buffers, sizeof(read_data)));
+ BOOST_CHECK(!error);
}
void async_read_handler(const boost::system::error_code& e,
@@ -617,6 +722,88 @@
ios.run();
BOOST_CHECK(called);
BOOST_CHECK(s.check(buffers, 50));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read(s, buffers, old_style_transfer_all,
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read(s, buffers, old_style_transfer_all,
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read(s, buffers, old_style_transfer_all,
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read(s, buffers, short_transfer,
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read(s, buffers, short_transfer,
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read(s, buffers, short_transfer,
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(buffers, sizeof(read_data)));
}
test_suite* init_unit_test_suite(int, char*[])
Added: trunk/libs/asio/test/read_at.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/test/read_at.cpp 2008-08-28 08:11:47 EDT (Thu, 28 Aug 2008)
@@ -0,0 +1,1466 @@
+//
+// read_at.cpp
+// ~~~~~~~~~~~
+//
+// Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+// Disable autolinking for unit tests.
+#if !defined(BOOST_ALL_NO_LIB)
+#define BOOST_ALL_NO_LIB 1
+#endif // !defined(BOOST_ALL_NO_LIB)
+
+// Test that header file is self-contained.
+#include <boost/asio/read_at.hpp>
+
+#include <boost/bind.hpp>
+#include <boost/noncopyable.hpp>
+#include <cstring>
+#include <boost/asio.hpp>
+#include "unit_test.hpp"
+
+using namespace std; // For memcmp, memcpy and memset.
+
+class test_random_access_device
+ : private boost::noncopyable
+{
+public:
+ typedef boost::asio::io_service io_service_type;
+
+ test_random_access_device(boost::asio::io_service& io_service)
+ : io_service_(io_service),
+ length_(0),
+ next_read_length_(0)
+ {
+ }
+
+ io_service_type& get_io_service()
+ {
+ return io_service_;
+ }
+
+ void reset(const void* data, size_t length)
+ {
+ BOOST_CHECK(length <= max_length);
+
+ length_ = 0;
+ while (length_ + length < max_length)
+ {
+ memcpy(data_ + length_, data, length);
+ length_ += length;
+ }
+
+ next_read_length_ = length;
+ }
+
+ void next_read_length(size_t length)
+ {
+ next_read_length_ = length;
+ }
+
+ template <typename Const_Buffers>
+ bool check(boost::uint64_t offset,
+ const Const_Buffers& buffers, size_t length)
+ {
+ if (offset + length > max_length)
+ return false;
+
+ typename Const_Buffers::const_iterator iter = buffers.begin();
+ typename Const_Buffers::const_iterator end = buffers.end();
+ size_t checked_length = 0;
+ for (; iter != end && checked_length < length; ++iter)
+ {
+ size_t buffer_length = boost::asio::buffer_size(*iter);
+ if (buffer_length > length - checked_length)
+ buffer_length = length - checked_length;
+ if (memcmp(data_ + offset + checked_length,
+ boost::asio::buffer_cast<const void*>(*iter), buffer_length) != 0)
+ return false;
+ checked_length += buffer_length;
+ }
+
+ return true;
+ }
+
+ template <typename Mutable_Buffers>
+ size_t read_some_at(boost::uint64_t offset, const Mutable_Buffers& buffers)
+ {
+ size_t total_length = 0;
+
+ typename Mutable_Buffers::const_iterator iter = buffers.begin();
+ typename Mutable_Buffers::const_iterator end = buffers.end();
+ for (; iter != end && total_length < next_read_length_; ++iter)
+ {
+ size_t length = boost::asio::buffer_size(*iter);
+ if (length > length_ - offset)
+ length = length_ - offset;
+
+ if (length > next_read_length_ - total_length)
+ length = next_read_length_ - total_length;
+
+ memcpy(boost::asio::buffer_cast<void*>(*iter),
+ data_ + offset, length);
+ offset += length;
+ total_length += length;
+ }
+
+ return total_length;
+ }
+
+ template <typename Mutable_Buffers>
+ size_t read_some_at(boost::uint64_t offset,
+ const Mutable_Buffers& buffers, boost::system::error_code& ec)
+ {
+ ec = boost::system::error_code();
+ return read_some_at(offset, buffers);
+ }
+
+ template <typename Mutable_Buffers, typename Handler>
+ void async_read_some_at(boost::uint64_t offset,
+ const Mutable_Buffers& buffers, Handler handler)
+ {
+ size_t bytes_transferred = read_some_at(offset, buffers);
+ io_service_.post(boost::asio::detail::bind_handler(
+ handler, boost::system::error_code(), bytes_transferred));
+ }
+
+private:
+ io_service_type& io_service_;
+ enum { max_length = 8192 };
+ char data_[max_length];
+ size_t length_;
+ size_t next_read_length_;
+};
+
+static const char read_data[]
+ = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+
+void test_3_arg_read_at()
+{
+ boost::asio::io_service ios;
+ test_random_access_device s(ios);
+ char read_buf[sizeof(read_data)];
+ boost::asio::mutable_buffers_1 buffers
+ = boost::asio::buffer(read_buf, sizeof(read_buf));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ size_t bytes_transferred = boost::asio::read_at(s, 0, buffers);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 0, buffers);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 0, buffers);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+}
+
+bool old_style_transfer_all(const boost::system::error_code& ec,
+ size_t bytes_transferred)
+{
+ return !!ec;
+}
+
+size_t short_transfer(const boost::system::error_code& ec,
+ size_t bytes_transferred)
+{
+ return !!ec ? 0 : 3;
+}
+
+void test_4_arg_read_at()
+{
+ boost::asio::io_service ios;
+ test_random_access_device s(ios);
+ char read_buf[sizeof(read_data)];
+ boost::asio::mutable_buffers_1 buffers
+ = boost::asio::buffer(read_buf, sizeof(read_buf));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ size_t bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ boost::asio::transfer_all());
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ boost::asio::transfer_all());
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ boost::asio::transfer_all());
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ boost::asio::transfer_all());
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ boost::asio::transfer_all());
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ boost::asio::transfer_all());
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ boost::asio::transfer_at_least(1));
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(1));
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ boost::asio::transfer_at_least(1));
+ BOOST_CHECK(bytes_transferred == 1);
+ BOOST_CHECK(s.check(0, buffers, 1));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(1));
+ BOOST_CHECK(bytes_transferred == 1);
+ BOOST_CHECK(s.check(1234, buffers, 1));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ boost::asio::transfer_at_least(1));
+ BOOST_CHECK(bytes_transferred == 10);
+ BOOST_CHECK(s.check(0, buffers, 10));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(1));
+ BOOST_CHECK(bytes_transferred == 10);
+ BOOST_CHECK(s.check(1234, buffers, 10));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ boost::asio::transfer_at_least(10));
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(10));
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ boost::asio::transfer_at_least(10));
+ BOOST_CHECK(bytes_transferred == 10);
+ BOOST_CHECK(s.check(0, buffers, 10));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(10));
+ BOOST_CHECK(bytes_transferred == 10);
+ BOOST_CHECK(s.check(1234, buffers, 10));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ boost::asio::transfer_at_least(10));
+ BOOST_CHECK(bytes_transferred == 10);
+ BOOST_CHECK(s.check(0, buffers, 10));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(10));
+ BOOST_CHECK(bytes_transferred == 10);
+ BOOST_CHECK(s.check(1234, buffers, 10));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ boost::asio::transfer_at_least(42));
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(42));
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ boost::asio::transfer_at_least(42));
+ BOOST_CHECK(bytes_transferred == 42);
+ BOOST_CHECK(s.check(0, buffers, 42));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(42));
+ BOOST_CHECK(bytes_transferred == 42);
+ BOOST_CHECK(s.check(1234, buffers, 42));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ boost::asio::transfer_at_least(42));
+ BOOST_CHECK(bytes_transferred == 50);
+ BOOST_CHECK(s.check(0, buffers, 50));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(42));
+ BOOST_CHECK(bytes_transferred == 50);
+ BOOST_CHECK(s.check(1234, buffers, 50));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ old_style_transfer_all);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ old_style_transfer_all);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ old_style_transfer_all);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ old_style_transfer_all);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ old_style_transfer_all);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ old_style_transfer_all);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 0, buffers, short_transfer);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers, short_transfer);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 0, buffers, short_transfer);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers, short_transfer);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 0, buffers, short_transfer);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers, short_transfer);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+}
+
+void test_5_arg_read_at()
+{
+ boost::asio::io_service ios;
+ test_random_access_device s(ios);
+ char read_buf[sizeof(read_data)];
+ boost::asio::mutable_buffers_1 buffers
+ = boost::asio::buffer(read_buf, sizeof(read_buf));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ boost::system::error_code error;
+ size_t bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ boost::asio::transfer_all(), error);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ boost::asio::transfer_all(), error);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ boost::asio::transfer_all(), error);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ boost::asio::transfer_all(), error);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ boost::asio::transfer_all(), error);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ boost::asio::transfer_all(), error);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ boost::asio::transfer_at_least(1), error);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(1), error);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ boost::asio::transfer_at_least(1), error);
+ BOOST_CHECK(bytes_transferred == 1);
+ BOOST_CHECK(s.check(0, buffers, 1));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(1), error);
+ BOOST_CHECK(bytes_transferred == 1);
+ BOOST_CHECK(s.check(1234, buffers, 1));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ boost::asio::transfer_at_least(1), error);
+ BOOST_CHECK(bytes_transferred == 10);
+ BOOST_CHECK(s.check(0, buffers, 10));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(1), error);
+ BOOST_CHECK(bytes_transferred == 10);
+ BOOST_CHECK(s.check(1234, buffers, 10));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ boost::asio::transfer_at_least(10), error);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(10), error);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ boost::asio::transfer_at_least(10), error);
+ BOOST_CHECK(bytes_transferred == 10);
+ BOOST_CHECK(s.check(0, buffers, 10));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(10), error);
+ BOOST_CHECK(bytes_transferred == 10);
+ BOOST_CHECK(s.check(1234, buffers, 10));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ boost::asio::transfer_at_least(10), error);
+ BOOST_CHECK(bytes_transferred == 10);
+ BOOST_CHECK(s.check(0, buffers, 10));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(10), error);
+ BOOST_CHECK(bytes_transferred == 10);
+ BOOST_CHECK(s.check(1234, buffers, 10));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ boost::asio::transfer_at_least(42), error);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(42), error);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ boost::asio::transfer_at_least(42), error);
+ BOOST_CHECK(bytes_transferred == 42);
+ BOOST_CHECK(s.check(0, buffers, 42));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(42), error);
+ BOOST_CHECK(bytes_transferred == 42);
+ BOOST_CHECK(s.check(1234, buffers, 42));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ boost::asio::transfer_at_least(42), error);
+ BOOST_CHECK(bytes_transferred == 50);
+ BOOST_CHECK(s.check(0, buffers, 50));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(42), error);
+ BOOST_CHECK(bytes_transferred == 50);
+ BOOST_CHECK(s.check(1234, buffers, 50));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ old_style_transfer_all, error);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ old_style_transfer_all, error);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ old_style_transfer_all, error);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ old_style_transfer_all, error);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ old_style_transfer_all, error);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ old_style_transfer_all, error);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ short_transfer, error);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ short_transfer, error);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ short_transfer, error);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ short_transfer, error);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read_at(s, 0, buffers,
+ short_transfer, error);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+ BOOST_CHECK(!error);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::read_at(s, 1234, buffers,
+ short_transfer, error);
+ BOOST_CHECK(bytes_transferred == sizeof(read_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+ BOOST_CHECK(!error);
+}
+
+void async_read_handler(const boost::system::error_code& e,
+ size_t bytes_transferred, size_t expected_bytes_transferred, bool* called)
+{
+ *called = true;
+ BOOST_CHECK(!e);
+ BOOST_CHECK(bytes_transferred == expected_bytes_transferred);
+}
+
+void test_4_arg_async_read_at()
+{
+ boost::asio::io_service ios;
+ test_random_access_device s(ios);
+ char read_buf[sizeof(read_data)];
+ boost::asio::mutable_buffers_1 buffers
+ = boost::asio::buffer(read_buf, sizeof(read_buf));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ bool called = false;
+ boost::asio::async_read_at(s, 0, buffers,
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 1234, buffers,
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 0, buffers,
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 1234, buffers,
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 0, buffers,
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 1234, buffers,
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+}
+
+void test_5_arg_async_read_at()
+{
+ boost::asio::io_service ios;
+ test_random_access_device s(ios);
+ char read_buf[sizeof(read_data)];
+ boost::asio::mutable_buffers_1 buffers
+ = boost::asio::buffer(read_buf, sizeof(read_buf));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ bool called = false;
+ boost::asio::async_read_at(s, 0, buffers,
+ boost::asio::transfer_all(),
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 1234, buffers,
+ boost::asio::transfer_all(),
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 0, buffers,
+ boost::asio::transfer_all(),
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 1234, buffers,
+ boost::asio::transfer_all(),
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 0, buffers,
+ boost::asio::transfer_all(),
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 1234, buffers,
+ boost::asio::transfer_all(),
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 0, buffers,
+ boost::asio::transfer_at_least(1),
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(1),
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 0, buffers,
+ boost::asio::transfer_at_least(1),
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ 1, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, 1));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(1),
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ 1, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, 1));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 0, buffers,
+ boost::asio::transfer_at_least(1),
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ 10, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, 10));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(1),
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ 10, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, 10));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 0, buffers,
+ boost::asio::transfer_at_least(10),
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(10),
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 0, buffers,
+ boost::asio::transfer_at_least(10),
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ 10, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, 10));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(10),
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ 10, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, 10));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 0, buffers,
+ boost::asio::transfer_at_least(10),
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ 10, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, 10));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(10),
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ 10, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, 10));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 0, buffers,
+ boost::asio::transfer_at_least(42),
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(42),
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 0, buffers,
+ boost::asio::transfer_at_least(42),
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ 42, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, 42));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(42),
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ 42, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, 42));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 0, buffers,
+ boost::asio::transfer_at_least(42),
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ 50, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, 50));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(42),
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ 50, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, 50));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 0, buffers, old_style_transfer_all,
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 1234, buffers, old_style_transfer_all,
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 0, buffers, old_style_transfer_all,
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 1234, buffers, old_style_transfer_all,
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 0, buffers, old_style_transfer_all,
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 1234, buffers, old_style_transfer_all,
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 0, buffers, short_transfer,
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 1234, buffers, short_transfer,
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 0, buffers, short_transfer,
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 1234, buffers, short_transfer,
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 0, buffers, short_transfer,
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, sizeof(read_data)));
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ memset(read_buf, 0, sizeof(read_buf));
+ called = false;
+ boost::asio::async_read_at(s, 1234, buffers, short_transfer,
+ boost::bind(async_read_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(read_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, sizeof(read_data)));
+}
+
+test_suite* init_unit_test_suite(int, char*[])
+{
+ test_suite* test = BOOST_TEST_SUITE("read");
+ test->add(BOOST_TEST_CASE(&test_3_arg_read_at));
+ test->add(BOOST_TEST_CASE(&test_4_arg_read_at));
+ test->add(BOOST_TEST_CASE(&test_5_arg_read_at));
+ test->add(BOOST_TEST_CASE(&test_4_arg_async_read_at));
+ test->add(BOOST_TEST_CASE(&test_5_arg_async_read_at));
+ return test;
+}
Modified: trunk/libs/asio/test/write.cpp
==============================================================================
--- trunk/libs/asio/test/write.cpp (original)
+++ trunk/libs/asio/test/write.cpp 2008-08-28 08:11:47 EDT (Thu, 28 Aug 2008)
@@ -39,7 +39,7 @@
memset(data_, 0, max_length);
}
- io_service_type& io_service()
+ io_service_type& get_io_service()
{
return io_service_;
}
@@ -159,6 +159,18 @@
BOOST_CHECK(s.check(buffers, sizeof(write_data)));
}
+bool old_style_transfer_all(const boost::system::error_code& ec,
+ size_t bytes_transferred)
+{
+ return !!ec;
+}
+
+size_t short_transfer(const boost::system::error_code& ec,
+ size_t bytes_transferred)
+{
+ return !!ec ? 0 : 3;
+}
+
void test_3_arg_write()
{
boost::asio::io_service ios;
@@ -245,6 +257,40 @@
boost::asio::transfer_at_least(42));
BOOST_CHECK(bytes_transferred == 50);
BOOST_CHECK(s.check(buffers, 50));
+
+ s.reset();
+ bytes_transferred = boost::asio::write(s, buffers, old_style_transfer_all);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(1);
+ bytes_transferred = boost::asio::write(s, buffers, old_style_transfer_all);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(10);
+ bytes_transferred = boost::asio::write(s, buffers, old_style_transfer_all);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(buffers, sizeof(write_data)));
+
+ s.reset();
+ bytes_transferred = boost::asio::write(s, buffers, short_transfer);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(1);
+ bytes_transferred = boost::asio::write(s, buffers, short_transfer);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(10);
+ bytes_transferred = boost::asio::write(s, buffers, short_transfer);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(buffers, sizeof(write_data)));
}
void test_4_arg_write()
@@ -357,6 +403,53 @@
BOOST_CHECK(bytes_transferred == 50);
BOOST_CHECK(s.check(buffers, 50));
BOOST_CHECK(!error);
+
+ s.reset();
+ bytes_transferred = boost::asio::write(s, buffers,
+ old_style_transfer_all, error);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(buffers, sizeof(write_data)));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ s.next_write_length(1);
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write(s, buffers,
+ old_style_transfer_all, error);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(buffers, sizeof(write_data)));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ s.next_write_length(10);
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write(s, buffers,
+ old_style_transfer_all, error);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(buffers, sizeof(write_data)));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ bytes_transferred = boost::asio::write(s, buffers, short_transfer, error);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(buffers, sizeof(write_data)));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ s.next_write_length(1);
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write(s, buffers, short_transfer, error);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(buffers, sizeof(write_data)));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ s.next_write_length(10);
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write(s, buffers, short_transfer, error);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(buffers, sizeof(write_data)));
+ BOOST_CHECK(!error);
}
void async_write_handler(const boost::system::error_code& e,
@@ -571,6 +664,82 @@
ios.run();
BOOST_CHECK(called);
BOOST_CHECK(s.check(buffers, 50));
+
+ s.reset();
+ called = false;
+ boost::asio::async_write(s, buffers, old_style_transfer_all,
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(1);
+ called = false;
+ boost::asio::async_write(s, buffers, old_style_transfer_all,
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(10);
+ called = false;
+ boost::asio::async_write(s, buffers, old_style_transfer_all,
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(buffers, sizeof(write_data)));
+
+ s.reset();
+ called = false;
+ boost::asio::async_write(s, buffers, short_transfer,
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(1);
+ called = false;
+ boost::asio::async_write(s, buffers, short_transfer,
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(10);
+ called = false;
+ boost::asio::async_write(s, buffers, short_transfer,
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(buffers, sizeof(write_data)));
}
test_suite* init_unit_test_suite(int, char*[])
Added: trunk/libs/asio/test/write_at.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/test/write_at.cpp 2008-08-28 08:11:47 EDT (Thu, 28 Aug 2008)
@@ -0,0 +1,1346 @@
+//
+// write_at.cpp
+// ~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+// Disable autolinking for unit tests.
+#if !defined(BOOST_ALL_NO_LIB)
+#define BOOST_ALL_NO_LIB 1
+#endif // !defined(BOOST_ALL_NO_LIB)
+
+// Test that header file is self-contained.
+#include <boost/asio/write_at.hpp>
+
+#include <boost/bind.hpp>
+#include <boost/noncopyable.hpp>
+#include <cstring>
+#include <boost/asio.hpp>
+#include "unit_test.hpp"
+
+using namespace std; // For memcmp, memcpy and memset.
+
+class test_random_access_device
+ : private boost::noncopyable
+{
+public:
+ typedef boost::asio::io_service io_service_type;
+
+ test_random_access_device(boost::asio::io_service& io_service)
+ : io_service_(io_service),
+ length_(max_length),
+ next_write_length_(max_length)
+ {
+ memset(data_, 0, max_length);
+ }
+
+ io_service_type& get_io_service()
+ {
+ return io_service_;
+ }
+
+ void reset()
+ {
+ memset(data_, 0, max_length);
+ next_write_length_ = max_length;
+ }
+
+ void next_write_length(size_t length)
+ {
+ next_write_length_ = length;
+ }
+
+ template <typename Const_Buffers>
+ bool check(boost::uint64_t offset,
+ const Const_Buffers& buffers, size_t length)
+ {
+ if (offset + length > max_length)
+ return false;
+
+ typename Const_Buffers::const_iterator iter = buffers.begin();
+ typename Const_Buffers::const_iterator end = buffers.end();
+ size_t checked_length = 0;
+ for (; iter != end && checked_length < length; ++iter)
+ {
+ size_t buffer_length = boost::asio::buffer_size(*iter);
+ if (buffer_length > length - checked_length)
+ buffer_length = length - checked_length;
+ if (memcmp(data_ + offset + checked_length,
+ boost::asio::buffer_cast<const void*>(*iter), buffer_length) != 0)
+ return false;
+ checked_length += buffer_length;
+ }
+
+ return true;
+ }
+
+ template <typename Const_Buffers>
+ size_t write_some_at(boost::uint64_t offset, const Const_Buffers& buffers)
+ {
+ size_t total_length = 0;
+
+ typename Const_Buffers::const_iterator iter = buffers.begin();
+ typename Const_Buffers::const_iterator end = buffers.end();
+ for (; iter != end && total_length < next_write_length_; ++iter)
+ {
+ size_t length = boost::asio::buffer_size(*iter);
+ if (length > length_ - offset)
+ length = length_ - offset;
+
+ if (length > next_write_length_ - total_length)
+ length = next_write_length_ - total_length;
+
+ memcpy(data_ + offset,
+ boost::asio::buffer_cast<const void*>(*iter), length);
+ offset += length;
+ total_length += length;
+ }
+
+ return total_length;
+ }
+
+ template <typename Const_Buffers>
+ size_t write_some_at(boost::uint64_t offset,
+ const Const_Buffers& buffers, boost::system::error_code& ec)
+ {
+ ec = boost::system::error_code();
+ return write_some_at(offset, buffers);
+ }
+
+ template <typename Const_Buffers, typename Handler>
+ void async_write_some_at(boost::uint64_t offset,
+ const Const_Buffers& buffers, Handler handler)
+ {
+ size_t bytes_transferred = write_some_at(offset, buffers);
+ io_service_.post(boost::asio::detail::bind_handler(
+ handler, boost::system::error_code(), bytes_transferred));
+ }
+
+private:
+ io_service_type& io_service_;
+ enum { max_length = 8192 };
+ char data_[max_length];
+ size_t length_;
+ size_t next_write_length_;
+};
+
+static const char write_data[]
+ = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+
+void test_3_arg_write_at()
+{
+ boost::asio::io_service ios;
+ test_random_access_device s(ios);
+ boost::asio::const_buffers_1 buffers
+ = boost::asio::buffer(write_data, sizeof(write_data));
+
+ s.reset();
+ size_t bytes_transferred = boost::asio::write_at(s, 0, buffers);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+
+ s.reset();
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(1);
+ bytes_transferred = boost::asio::write_at(s, 0, buffers);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(1);
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(10);
+ bytes_transferred = boost::asio::write_at(s, 0, buffers);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(10);
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+}
+
+bool old_style_transfer_all(const boost::system::error_code& ec,
+ size_t bytes_transferred)
+{
+ return !!ec;
+}
+
+size_t short_transfer(const boost::system::error_code& ec,
+ size_t bytes_transferred)
+{
+ return !!ec ? 0 : 3;
+}
+
+void test_4_arg_write_at()
+{
+ boost::asio::io_service ios;
+ test_random_access_device s(ios);
+ boost::asio::const_buffers_1 buffers
+ = boost::asio::buffer(write_data, sizeof(write_data));
+
+ s.reset();
+ size_t bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ boost::asio::transfer_all());
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+
+ s.reset();
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ boost::asio::transfer_all());
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(1);
+ bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ boost::asio::transfer_all());
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(1);
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ boost::asio::transfer_all());
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(10);
+ bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ boost::asio::transfer_all());
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(10);
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ boost::asio::transfer_all());
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+
+ s.reset();
+ bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ boost::asio::transfer_at_least(1));
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+
+ s.reset();
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(1));
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(1);
+ bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ boost::asio::transfer_at_least(1));
+ BOOST_CHECK(bytes_transferred == 1);
+ BOOST_CHECK(s.check(0, buffers, 1));
+
+ s.reset();
+ s.next_write_length(1);
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(1));
+ BOOST_CHECK(bytes_transferred == 1);
+ BOOST_CHECK(s.check(1234, buffers, 1));
+
+ s.reset();
+ s.next_write_length(10);
+ bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ boost::asio::transfer_at_least(1));
+ BOOST_CHECK(bytes_transferred == 10);
+ BOOST_CHECK(s.check(0, buffers, 10));
+
+ s.reset();
+ s.next_write_length(10);
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(1));
+ BOOST_CHECK(bytes_transferred == 10);
+ BOOST_CHECK(s.check(1234, buffers, 10));
+
+ s.reset();
+ bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ boost::asio::transfer_at_least(10));
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+
+ s.reset();
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(10));
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(1);
+ bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ boost::asio::transfer_at_least(10));
+ BOOST_CHECK(bytes_transferred == 10);
+ BOOST_CHECK(s.check(0, buffers, 10));
+
+ s.reset();
+ s.next_write_length(1);
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(10));
+ BOOST_CHECK(bytes_transferred == 10);
+ BOOST_CHECK(s.check(1234, buffers, 10));
+
+ s.reset();
+ s.next_write_length(10);
+ bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ boost::asio::transfer_at_least(10));
+ BOOST_CHECK(bytes_transferred == 10);
+ BOOST_CHECK(s.check(0, buffers, 10));
+
+ s.reset();
+ s.next_write_length(10);
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(10));
+ BOOST_CHECK(bytes_transferred == 10);
+ BOOST_CHECK(s.check(1234, buffers, 10));
+
+ s.reset();
+ bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ boost::asio::transfer_at_least(42));
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+
+ s.reset();
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(42));
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(1);
+ bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ boost::asio::transfer_at_least(42));
+ BOOST_CHECK(bytes_transferred == 42);
+ BOOST_CHECK(s.check(0, buffers, 42));
+
+ s.reset();
+ s.next_write_length(1);
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(42));
+ BOOST_CHECK(bytes_transferred == 42);
+ BOOST_CHECK(s.check(1234, buffers, 42));
+
+ s.reset();
+ s.next_write_length(10);
+ bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ boost::asio::transfer_at_least(42));
+ BOOST_CHECK(bytes_transferred == 50);
+ BOOST_CHECK(s.check(0, buffers, 50));
+
+ s.reset();
+ s.next_write_length(10);
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(42));
+ BOOST_CHECK(bytes_transferred == 50);
+ BOOST_CHECK(s.check(1234, buffers, 50));
+
+ s.reset();
+ bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ old_style_transfer_all);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+
+ s.reset();
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ old_style_transfer_all);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(1);
+ bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ old_style_transfer_all);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(1);
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ old_style_transfer_all);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(10);
+ bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ old_style_transfer_all);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(10);
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ old_style_transfer_all);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+
+ s.reset();
+ bytes_transferred = boost::asio::write_at(s, 0, buffers, short_transfer);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+
+ s.reset();
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers, short_transfer);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(1);
+ bytes_transferred = boost::asio::write_at(s, 0, buffers, short_transfer);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(1);
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers, short_transfer);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(10);
+ bytes_transferred = boost::asio::write_at(s, 0, buffers, short_transfer);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(10);
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers, short_transfer);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+}
+
+void test_5_arg_write_at()
+{
+ boost::asio::io_service ios;
+ test_random_access_device s(ios);
+ boost::asio::const_buffers_1 buffers
+ = boost::asio::buffer(write_data, sizeof(write_data));
+
+ s.reset();
+ boost::system::error_code error;
+ size_t bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ boost::asio::transfer_all(), error);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ boost::asio::transfer_all(), error);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ s.next_write_length(1);
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ boost::asio::transfer_all(), error);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ s.next_write_length(1);
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ boost::asio::transfer_all(), error);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ s.next_write_length(10);
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ boost::asio::transfer_all(), error);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ s.next_write_length(10);
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ boost::asio::transfer_all(), error);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ boost::asio::transfer_at_least(1), error);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(1), error);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ s.next_write_length(1);
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ boost::asio::transfer_at_least(1), error);
+ BOOST_CHECK(bytes_transferred == 1);
+ BOOST_CHECK(s.check(0, buffers, 1));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ s.next_write_length(1);
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(1), error);
+ BOOST_CHECK(bytes_transferred == 1);
+ BOOST_CHECK(s.check(1234, buffers, 1));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ s.next_write_length(10);
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ boost::asio::transfer_at_least(1), error);
+ BOOST_CHECK(bytes_transferred == 10);
+ BOOST_CHECK(s.check(0, buffers, 10));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ s.next_write_length(10);
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(1), error);
+ BOOST_CHECK(bytes_transferred == 10);
+ BOOST_CHECK(s.check(1234, buffers, 10));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ boost::asio::transfer_at_least(10), error);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(10), error);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ s.next_write_length(1);
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ boost::asio::transfer_at_least(10), error);
+ BOOST_CHECK(bytes_transferred == 10);
+ BOOST_CHECK(s.check(0, buffers, 10));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ s.next_write_length(1);
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(10), error);
+ BOOST_CHECK(bytes_transferred == 10);
+ BOOST_CHECK(s.check(1234, buffers, 10));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ s.next_write_length(10);
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ boost::asio::transfer_at_least(10), error);
+ BOOST_CHECK(bytes_transferred == 10);
+ BOOST_CHECK(s.check(0, buffers, 10));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ s.next_write_length(10);
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(10), error);
+ BOOST_CHECK(bytes_transferred == 10);
+ BOOST_CHECK(s.check(1234, buffers, 10));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ boost::asio::transfer_at_least(42), error);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(42), error);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ s.next_write_length(1);
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ boost::asio::transfer_at_least(42), error);
+ BOOST_CHECK(bytes_transferred == 42);
+ BOOST_CHECK(s.check(0, buffers, 42));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ s.next_write_length(1);
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(42), error);
+ BOOST_CHECK(bytes_transferred == 42);
+ BOOST_CHECK(s.check(1234, buffers, 42));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ s.next_write_length(10);
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ boost::asio::transfer_at_least(42), error);
+ BOOST_CHECK(bytes_transferred == 50);
+ BOOST_CHECK(s.check(0, buffers, 50));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ s.next_write_length(10);
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(42), error);
+ BOOST_CHECK(bytes_transferred == 50);
+ BOOST_CHECK(s.check(1234, buffers, 50));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ old_style_transfer_all, error);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ old_style_transfer_all, error);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ s.next_write_length(1);
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ old_style_transfer_all, error);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ s.next_write_length(1);
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ old_style_transfer_all, error);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ s.next_write_length(10);
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ old_style_transfer_all, error);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ s.next_write_length(10);
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ old_style_transfer_all, error);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ short_transfer, error);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ short_transfer, error);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ s.next_write_length(1);
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ short_transfer, error);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ s.next_write_length(1);
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ short_transfer, error);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ s.next_write_length(10);
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write_at(s, 0, buffers,
+ short_transfer, error);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+ BOOST_CHECK(!error);
+
+ s.reset();
+ s.next_write_length(10);
+ error = boost::system::error_code();
+ bytes_transferred = boost::asio::write_at(s, 1234, buffers,
+ short_transfer, error);
+ BOOST_CHECK(bytes_transferred == sizeof(write_data));
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+ BOOST_CHECK(!error);
+}
+
+void async_write_handler(const boost::system::error_code& e,
+ size_t bytes_transferred, size_t expected_bytes_transferred, bool* called)
+{
+ *called = true;
+ BOOST_CHECK(!e);
+ BOOST_CHECK(bytes_transferred == expected_bytes_transferred);
+}
+
+void test_4_arg_async_write_at()
+{
+ boost::asio::io_service ios;
+ test_random_access_device s(ios);
+ boost::asio::const_buffers_1 buffers
+ = boost::asio::buffer(write_data, sizeof(write_data));
+
+ s.reset();
+ bool called = false;
+ boost::asio::async_write_at(s, 0, buffers,
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+
+ s.reset();
+ called = false;
+ boost::asio::async_write_at(s, 1234, buffers,
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(1);
+ called = false;
+ boost::asio::async_write_at(s, 0, buffers,
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(1);
+ called = false;
+ boost::asio::async_write_at(s, 1234, buffers,
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(10);
+ called = false;
+ boost::asio::async_write_at(s, 0, buffers,
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(10);
+ called = false;
+ boost::asio::async_write_at(s, 1234, buffers,
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+ s.reset();
+ s.next_write_length(10);
+ called = false;
+ boost::asio::async_write_at(s, 0, buffers,
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+}
+
+void test_5_arg_async_write_at()
+{
+ boost::asio::io_service ios;
+ test_random_access_device s(ios);
+ boost::asio::const_buffers_1 buffers
+ = boost::asio::buffer(write_data, sizeof(write_data));
+
+ s.reset();
+ bool called = false;
+ boost::asio::async_write_at(s, 0, buffers,
+ boost::asio::transfer_all(),
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+
+ s.reset();
+ called = false;
+ boost::asio::async_write_at(s, 1234, buffers,
+ boost::asio::transfer_all(),
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(1);
+ called = false;
+ boost::asio::async_write_at(s, 0, buffers,
+ boost::asio::transfer_all(),
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(1);
+ called = false;
+ boost::asio::async_write_at(s, 1234, buffers,
+ boost::asio::transfer_all(),
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(10);
+ called = false;
+ boost::asio::async_write_at(s, 0, buffers,
+ boost::asio::transfer_all(),
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(10);
+ called = false;
+ boost::asio::async_write_at(s, 1234, buffers,
+ boost::asio::transfer_all(),
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+
+ s.reset();
+ called = false;
+ boost::asio::async_write_at(s, 0, buffers,
+ boost::asio::transfer_at_least(1),
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+
+ s.reset();
+ called = false;
+ boost::asio::async_write_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(1),
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(1);
+ called = false;
+ boost::asio::async_write_at(s, 0, buffers,
+ boost::asio::transfer_at_least(1),
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ 1, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, 1));
+
+ s.reset();
+ s.next_write_length(1);
+ called = false;
+ boost::asio::async_write_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(1),
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ 1, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, 1));
+
+ s.reset();
+ s.next_write_length(10);
+ called = false;
+ boost::asio::async_write_at(s, 0, buffers,
+ boost::asio::transfer_at_least(1),
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ 10, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, 10));
+
+ s.reset();
+ s.next_write_length(10);
+ called = false;
+ boost::asio::async_write_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(1),
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ 10, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, 10));
+
+ s.reset();
+ called = false;
+ boost::asio::async_write_at(s, 0, buffers,
+ boost::asio::transfer_at_least(10),
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+
+ s.reset();
+ called = false;
+ boost::asio::async_write_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(10),
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(1);
+ called = false;
+ boost::asio::async_write_at(s, 0, buffers,
+ boost::asio::transfer_at_least(10),
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ 10, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, 10));
+
+ s.reset();
+ s.next_write_length(1);
+ called = false;
+ boost::asio::async_write_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(10),
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ 10, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, 10));
+
+ s.reset();
+ s.next_write_length(10);
+ called = false;
+ boost::asio::async_write_at(s, 0, buffers,
+ boost::asio::transfer_at_least(10),
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ 10, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, 10));
+
+ s.reset();
+ s.next_write_length(10);
+ called = false;
+ boost::asio::async_write_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(10),
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ 10, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, 10));
+
+ s.reset();
+ called = false;
+ boost::asio::async_write_at(s, 0, buffers,
+ boost::asio::transfer_at_least(42),
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+
+ s.reset();
+ called = false;
+ boost::asio::async_write_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(42),
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(1);
+ called = false;
+ boost::asio::async_write_at(s, 0, buffers,
+ boost::asio::transfer_at_least(42),
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ 42, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, 42));
+
+ s.reset();
+ s.next_write_length(1);
+ called = false;
+ boost::asio::async_write_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(42),
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ 42, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, 42));
+
+ s.reset();
+ s.next_write_length(10);
+ called = false;
+ boost::asio::async_write_at(s, 0, buffers,
+ boost::asio::transfer_at_least(42),
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ 50, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, 50));
+
+ s.reset();
+ s.next_write_length(10);
+ called = false;
+ boost::asio::async_write_at(s, 1234, buffers,
+ boost::asio::transfer_at_least(42),
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ 50, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, 50));
+
+ s.reset();
+ called = false;
+ boost::asio::async_write_at(s, 0, buffers, old_style_transfer_all,
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+
+ s.reset();
+ called = false;
+ boost::asio::async_write_at(s, 1234, buffers, old_style_transfer_all,
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(1);
+ called = false;
+ boost::asio::async_write_at(s, 0, buffers, old_style_transfer_all,
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(1);
+ called = false;
+ boost::asio::async_write_at(s, 1234, buffers, old_style_transfer_all,
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(10);
+ called = false;
+ boost::asio::async_write_at(s, 0, buffers, old_style_transfer_all,
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(10);
+ called = false;
+ boost::asio::async_write_at(s, 1234, buffers, old_style_transfer_all,
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+
+ s.reset();
+ called = false;
+ boost::asio::async_write_at(s, 0, buffers, short_transfer,
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+
+ s.reset();
+ called = false;
+ boost::asio::async_write_at(s, 1234, buffers, short_transfer,
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(1);
+ called = false;
+ boost::asio::async_write_at(s, 0, buffers, short_transfer,
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(1);
+ called = false;
+ boost::asio::async_write_at(s, 1234, buffers, short_transfer,
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(10);
+ called = false;
+ boost::asio::async_write_at(s, 0, buffers, short_transfer,
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(0, buffers, sizeof(write_data)));
+
+ s.reset();
+ s.next_write_length(10);
+ called = false;
+ boost::asio::async_write_at(s, 1234, buffers, short_transfer,
+ boost::bind(async_write_handler,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ sizeof(write_data), &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(s.check(1234, buffers, sizeof(write_data)));
+}
+
+test_suite* init_unit_test_suite(int, char*[])
+{
+ test_suite* test = BOOST_TEST_SUITE("write_at");
+ test->add(BOOST_TEST_CASE(&test_3_arg_write_at));
+ test->add(BOOST_TEST_CASE(&test_4_arg_write_at));
+ test->add(BOOST_TEST_CASE(&test_5_arg_write_at));
+ test->add(BOOST_TEST_CASE(&test_4_arg_async_write_at));
+ test->add(BOOST_TEST_CASE(&test_5_arg_async_write_at));
+ return test;
+}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk