New move support for async_read_at.

This commit is contained in:
Christopher Kohlhoff 2011-05-02 21:54:53 +10:00
parent bc835587fd
commit 9bd0e8faa1
2 changed files with 138 additions and 39 deletions

View File

@ -153,6 +153,28 @@ namespace detail
{
}
#if defined(ASIO_HAS_MOVE)
write_at_op(const write_at_op& other)
: detail::base_form_completion_cond<CompletionCondition>(other),
device_(other.device),
offset_(other.offset),
buffers_(other.buffers_),
total_transferred_(other.total_transferred_),
handler_(other.handler_)
{
}
write_at_op(write_at_op&& other)
: detail::base_form_completion_cond<CompletionCondition>(other),
device_(other.device),
offset_(other.offset),
buffers_(other.buffers_),
total_transferred_(other.total_transferred_),
handler_(ASIO_MOVE_CAST(WriteHandler)(other.handler_))
{
}
#endif // defined(ASIO_HAS_MOVE)
void operator()(const asio::error_code& ec,
std::size_t bytes_transferred, int start = 0)
{
@ -163,7 +185,8 @@ namespace detail
for (;;)
{
device_.async_write_some_at(
offset_ + total_transferred_, buffers_, *this);
offset_ + total_transferred_, buffers_,
ASIO_MOVE_CAST(write_at_op)(*this));
return; default:
total_transferred_ += bytes_transferred;
buffers_.consume(bytes_transferred);
@ -207,6 +230,28 @@ namespace detail
{
}
#if defined(ASIO_HAS_MOVE)
write_at_op(const write_at_op& other)
: detail::base_form_completion_cond<CompletionCondition>(other),
device_(other.device),
offset_(other.offset),
buffer_(other.buffer_),
total_transferred_(other.total_transferred_),
handler_(other.handler_)
{
}
write_at_op(write_at_op&& other)
: detail::base_form_completion_cond<CompletionCondition>(other),
device_(other.device),
offset_(other.offset),
buffer_(other.buffer_),
total_transferred_(other.total_transferred_),
handler_(ASIO_MOVE_CAST(WriteHandler)(other.handler_))
{
}
#endif // defined(ASIO_HAS_MOVE)
void operator()(const asio::error_code& ec,
std::size_t bytes_transferred, int start = 0)
{
@ -218,7 +263,8 @@ namespace detail
for (;;)
{
device_.async_write_some_at(offset_ + total_transferred_,
asio::buffer(buffer_ + total_transferred_, n), *this);
asio::buffer(buffer_ + total_transferred_, n),
ASIO_MOVE_CAST(write_at_op)(*this));
return; default:
total_transferred_ += bytes_transferred;
if ((!ec && bytes_transferred == 0)
@ -260,6 +306,28 @@ namespace detail
{
}
#if defined(ASIO_HAS_MOVE)
write_at_op(const write_at_op& other)
: detail::base_form_completion_cond<CompletionCondition>(other),
device_(other.device),
offset_(other.offset),
buffer_(other.buffer_),
total_transferred_(other.total_transferred_),
handler_(other.handler_)
{
}
write_at_op(write_at_op&& other)
: detail::base_form_completion_cond<CompletionCondition>(other),
device_(other.device),
offset_(other.offset),
buffer_(other.buffer_),
total_transferred_(other.total_transferred_),
handler_(ASIO_MOVE_CAST(WriteHandler)(other.handler_))
{
}
#endif // defined(ASIO_HAS_MOVE)
void operator()(const asio::error_code& ec,
std::size_t bytes_transferred, int start = 0)
{
@ -271,7 +339,8 @@ namespace detail
for (;;)
{
device_.async_write_some_at(offset_ + total_transferred_,
asio::buffer(buffer_ + total_transferred_, n), *this);
asio::buffer(buffer_ + total_transferred_, n),
ASIO_MOVE_CAST(write_at_op)(*this));
return; default:
total_transferred_ += bytes_transferred;
if ((!ec && bytes_transferred == 0)
@ -333,21 +402,35 @@ namespace detail
asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
typename CompletionCondition, typename WriteHandler>
inline write_at_op<AsyncRandomAccessWriteDevice,
ConstBufferSequence, CompletionCondition, WriteHandler>
make_write_at_op(AsyncRandomAccessWriteDevice& d,
boost::uint64_t offset, const ConstBufferSequence& buffers,
CompletionCondition completion_condition, WriteHandler handler)
{
return write_at_op<AsyncRandomAccessWriteDevice,
ConstBufferSequence, CompletionCondition, WriteHandler>(
d, offset, buffers, completion_condition, handler);
}
} // namespace detail
template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
typename CompletionCondition, typename WriteHandler>
inline void async_write_at(AsyncRandomAccessWriteDevice& d,
boost::uint64_t offset, const ConstBufferSequence& buffers,
CompletionCondition completion_condition, WriteHandler handler)
CompletionCondition completion_condition,
ASIO_MOVE_ARG(WriteHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a WriteHandler.
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
detail::write_at_op<AsyncRandomAccessWriteDevice,
ConstBufferSequence, CompletionCondition, WriteHandler>(
d, offset, buffers, completion_condition, handler)(
detail::make_write_at_op(
d, offset, buffers, completion_condition,
ASIO_MOVE_CAST(WriteHandler)(handler))(
asio::error_code(), 0, 1);
}
@ -355,15 +438,15 @@ template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
typename WriteHandler>
inline void async_write_at(AsyncRandomAccessWriteDevice& d,
boost::uint64_t offset, const ConstBufferSequence& buffers,
WriteHandler handler)
ASIO_MOVE_ARG(WriteHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a WriteHandler.
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
detail::write_at_op<AsyncRandomAccessWriteDevice,
ConstBufferSequence, detail::transfer_all_t, WriteHandler>(
d, offset, buffers, transfer_all(), handler)(
detail::make_write_at_op(
d, offset, buffers, transfer_all(),
ASIO_MOVE_CAST(WriteHandler)(handler))(
asio::error_code(), 0, 1);
}
@ -371,8 +454,7 @@ inline void async_write_at(AsyncRandomAccessWriteDevice& d,
namespace detail
{
template <typename AsyncRandomAccessWriteDevice,
typename Allocator, typename WriteHandler>
template <typename Allocator, typename WriteHandler>
class write_at_streambuf_op
{
public:
@ -384,6 +466,20 @@ namespace detail
{
}
#if defined(ASIO_HAS_MOVE)
write_at_streambuf_op(const write_at_streambuf_op& other)
: streambuf_(other.streambuf_),
handler_(other.handler_)
{
}
write_at_streambuf_op(write_at_streambuf_op&& other)
: streambuf_(other.streambuf_),
handler_(ASIO_MOVE_CAST(WriteHandler)(other.handler_))
{
}
#endif // defined(ASIO_HAS_MOVE)
void operator()(const asio::error_code& ec,
const std::size_t bytes_transferred)
{
@ -396,75 +492,76 @@ namespace detail
WriteHandler handler_;
};
template <typename AsyncRandomAccessWriteDevice, typename Allocator,
typename WriteHandler>
template <typename Allocator, typename WriteHandler>
inline void* asio_handler_allocate(std::size_t size,
write_at_streambuf_op<AsyncRandomAccessWriteDevice,
Allocator, WriteHandler>* this_handler)
write_at_streambuf_op<Allocator, WriteHandler>* this_handler)
{
return asio_handler_alloc_helpers::allocate(
size, this_handler->handler_);
}
template <typename AsyncRandomAccessWriteDevice, typename Allocator,
typename WriteHandler>
template <typename Allocator, typename WriteHandler>
inline void asio_handler_deallocate(void* pointer, std::size_t size,
write_at_streambuf_op<AsyncRandomAccessWriteDevice,
Allocator, WriteHandler>* this_handler)
write_at_streambuf_op<Allocator, WriteHandler>* this_handler)
{
asio_handler_alloc_helpers::deallocate(
pointer, size, this_handler->handler_);
}
template <typename Function, typename AsyncRandomAccessWriteDevice,
typename Allocator, typename WriteHandler>
template <typename Function, typename Allocator, typename WriteHandler>
inline void asio_handler_invoke(Function& function,
write_at_streambuf_op<AsyncRandomAccessWriteDevice,
Allocator, WriteHandler>* this_handler)
write_at_streambuf_op<Allocator, WriteHandler>* this_handler)
{
asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
template <typename Function, typename AsyncRandomAccessWriteDevice,
typename Allocator, typename WriteHandler>
template <typename Function, typename Allocator, typename WriteHandler>
inline void asio_handler_invoke(const Function& function,
write_at_streambuf_op<AsyncRandomAccessWriteDevice,
Allocator, WriteHandler>* this_handler)
write_at_streambuf_op<Allocator, WriteHandler>* this_handler)
{
asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
template <typename Allocator, typename WriteHandler>
inline write_at_streambuf_op<Allocator, WriteHandler>
make_write_at_streambuf_op(
asio::basic_streambuf<Allocator>& b, WriteHandler handler)
{
return write_at_streambuf_op<Allocator, WriteHandler>(b, handler);
}
} // namespace detail
template <typename AsyncRandomAccessWriteDevice, typename Allocator,
typename CompletionCondition, typename WriteHandler>
inline void async_write_at(AsyncRandomAccessWriteDevice& d,
boost::uint64_t offset, asio::basic_streambuf<Allocator>& b,
CompletionCondition completion_condition, WriteHandler handler)
CompletionCondition completion_condition,
ASIO_MOVE_ARG(WriteHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a WriteHandler.
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
async_write_at(d, offset, b.data(), completion_condition,
detail::write_at_streambuf_op<
AsyncRandomAccessWriteDevice, Allocator, WriteHandler>(b, handler));
detail::make_write_at_streambuf_op(
b, ASIO_MOVE_CAST(WriteHandler)(handler)));
}
template <typename AsyncRandomAccessWriteDevice, typename Allocator,
typename WriteHandler>
inline void async_write_at(AsyncRandomAccessWriteDevice& d,
boost::uint64_t offset, asio::basic_streambuf<Allocator>& b,
WriteHandler handler)
ASIO_MOVE_ARG(WriteHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a WriteHandler.
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
async_write_at(d, offset, b.data(), transfer_all(),
detail::write_at_streambuf_op<
AsyncRandomAccessWriteDevice, Allocator, WriteHandler>(b, handler));
detail::make_write_at_streambuf_op(
b, ASIO_MOVE_CAST(WriteHandler)(handler)));
}
#endif // !defined(BOOST_NO_IOSTREAM)

View File

@ -445,7 +445,8 @@ std::size_t write_at(SyncRandomAccessWriteDevice& d, boost::uint64_t offset,
template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
typename WriteHandler>
void async_write_at(AsyncRandomAccessWriteDevice& d, boost::uint64_t offset,
const ConstBufferSequence& buffers, WriteHandler handler);
const ConstBufferSequence& buffers,
ASIO_MOVE_ARG(WriteHandler) handler);
/// Start an asynchronous operation to write a certain amount of data at the
/// specified offset.
@ -517,7 +518,8 @@ template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
typename CompletionCondition, typename WriteHandler>
void async_write_at(AsyncRandomAccessWriteDevice& d,
boost::uint64_t offset, const ConstBufferSequence& buffers,
CompletionCondition completion_condition, WriteHandler handler);
CompletionCondition completion_condition,
ASIO_MOVE_ARG(WriteHandler) handler);
#if !defined(BOOST_NO_IOSTREAM)
@ -564,7 +566,7 @@ void async_write_at(AsyncRandomAccessWriteDevice& d,
template <typename AsyncRandomAccessWriteDevice, typename Allocator,
typename WriteHandler>
void async_write_at(AsyncRandomAccessWriteDevice& d, boost::uint64_t offset,
basic_streambuf<Allocator>& b, WriteHandler handler);
basic_streambuf<Allocator>& b, ASIO_MOVE_ARG(WriteHandler) handler);
/// Start an asynchronous operation to write a certain amount of data at the
/// specified offset.
@ -624,7 +626,7 @@ template <typename AsyncRandomAccessWriteDevice, typename Allocator,
typename CompletionCondition, typename WriteHandler>
void async_write_at(AsyncRandomAccessWriteDevice& d, boost::uint64_t offset,
basic_streambuf<Allocator>& b, CompletionCondition completion_condition,
WriteHandler handler);
ASIO_MOVE_ARG(WriteHandler) handler);
#endif // !defined(BOOST_NO_IOSTREAM)