summaryrefslogtreecommitdiff
path: root/boost/asio/impl/read_at.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/asio/impl/read_at.hpp')
-rw-r--r--boost/asio/impl/read_at.hpp147
1 files changed, 81 insertions, 66 deletions
diff --git a/boost/asio/impl/read_at.hpp b/boost/asio/impl/read_at.hpp
index e3c31c543e..8152ef99a4 100644
--- a/boost/asio/impl/read_at.hpp
+++ b/boost/asio/impl/read_at.hpp
@@ -2,7 +2,7 @@
// impl/read_at.hpp
// ~~~~~~~~~~~~~~~~
//
-// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+// Copyright (c) 2003-2019 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)
@@ -29,6 +29,7 @@
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/handler_invoke_helpers.hpp>
#include <boost/asio/detail/handler_type_requirements.hpp>
+#include <boost/asio/detail/non_const_lvalue.hpp>
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/error.hpp>
@@ -71,7 +72,8 @@ std::size_t read_at(SyncRandomAccessReadDevice& d,
CompletionCondition completion_condition, boost::system::error_code& ec)
{
return detail::read_at_buffer_sequence(d, offset, buffers,
- boost::asio::buffer_sequence_begin(buffers), completion_condition, ec);
+ boost::asio::buffer_sequence_begin(buffers),
+ BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition), ec);
}
template <typename SyncRandomAccessReadDevice, typename MutableBufferSequence>
@@ -100,8 +102,8 @@ inline std::size_t read_at(SyncRandomAccessReadDevice& d,
CompletionCondition completion_condition)
{
boost::system::error_code ec;
- std::size_t bytes_transferred = read_at(
- d, offset, buffers, completion_condition, ec);
+ std::size_t bytes_transferred = read_at(d, offset, buffers,
+ BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition), ec);
boost::asio::detail::throw_error(ec, "read_at");
return bytes_transferred;
}
@@ -159,8 +161,8 @@ inline std::size_t read_at(SyncRandomAccessReadDevice& d,
CompletionCondition completion_condition)
{
boost::system::error_code ec;
- std::size_t bytes_transferred = read_at(
- d, offset, b, completion_condition, ec);
+ std::size_t bytes_transferred = read_at(d, offset, b,
+ BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition), ec);
boost::asio::detail::throw_error(ec, "read_at");
return bytes_transferred;
}
@@ -179,7 +181,7 @@ namespace detail
public:
read_at_op(AsyncRandomAccessReadDevice& device,
uint64_t offset, const MutableBufferSequence& buffers,
- CompletionCondition completion_condition, ReadHandler& handler)
+ CompletionCondition& completion_condition, ReadHandler& handler)
: detail::base_from_completion_cond<
CompletionCondition>(completion_condition),
device_(device),
@@ -202,10 +204,12 @@ namespace detail
}
read_at_op(read_at_op&& other)
- : detail::base_from_completion_cond<CompletionCondition>(other),
+ : detail::base_from_completion_cond<CompletionCondition>(
+ BOOST_ASIO_MOVE_CAST(detail::base_from_completion_cond<
+ CompletionCondition>)(other)),
device_(other.device_),
offset_(other.offset_),
- buffers_(other.buffers_),
+ buffers_(BOOST_ASIO_MOVE_CAST(buffers_type)(other.buffers_)),
start_(other.start_),
handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(other.handler_))
{
@@ -237,10 +241,12 @@ namespace detail
}
//private:
+ typedef boost::asio::detail::consuming_buffers<mutable_buffer,
+ MutableBufferSequence, MutableBufferIterator> buffers_type;
+
AsyncRandomAccessReadDevice& device_;
uint64_t offset_;
- boost::asio::detail::consuming_buffers<mutable_buffer,
- MutableBufferSequence, MutableBufferIterator> buffers_;
+ buffers_type buffers_;
int start_;
ReadHandler handler_;
};
@@ -306,7 +312,7 @@ namespace detail
typename CompletionCondition, typename ReadHandler>
inline void start_read_at_buffer_sequence_op(AsyncRandomAccessReadDevice& d,
uint64_t offset, const MutableBufferSequence& buffers,
- const MutableBufferIterator&, CompletionCondition completion_condition,
+ const MutableBufferIterator&, CompletionCondition& completion_condition,
ReadHandler& handler)
{
detail::read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
@@ -314,6 +320,27 @@ namespace detail
d, offset, buffers, completion_condition, handler)(
boost::system::error_code(), 0, 1);
}
+
+ struct initiate_async_read_at_buffer_sequence
+ {
+ template <typename ReadHandler, typename AsyncRandomAccessReadDevice,
+ typename MutableBufferSequence, typename CompletionCondition>
+ void operator()(BOOST_ASIO_MOVE_ARG(ReadHandler) handler,
+ AsyncRandomAccessReadDevice* d, uint64_t offset,
+ const MutableBufferSequence& buffers,
+ BOOST_ASIO_MOVE_ARG(CompletionCondition) completion_cond) const
+ {
+ // If you get an error on the following line it means that your handler
+ // does not meet the documented type requirements for a ReadHandler.
+ BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
+
+ non_const_lvalue<ReadHandler> handler2(handler);
+ non_const_lvalue<CompletionCondition> completion_cond2(completion_cond);
+ start_read_at_buffer_sequence_op(*d, offset, buffers,
+ boost::asio::buffer_sequence_begin(buffers),
+ completion_cond2.value, handler2.value);
+ }
+ };
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
@@ -369,18 +396,10 @@ async_read_at(AsyncRandomAccessReadDevice& d,
CompletionCondition completion_condition,
BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
{
- // If you get an error on the following line it means that your handler does
- // not meet the documented type requirements for a ReadHandler.
- BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
-
- async_completion<ReadHandler,
- void (boost::system::error_code, std::size_t)> init(handler);
-
- detail::start_read_at_buffer_sequence_op(d, offset, buffers,
- boost::asio::buffer_sequence_begin(buffers), completion_condition,
- init.completion_handler);
-
- return init.result.get();
+ return async_initiate<ReadHandler,
+ void (boost::system::error_code, std::size_t)>(
+ detail::initiate_async_read_at_buffer_sequence(), handler, &d, offset,
+ buffers, BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition));
}
template <typename AsyncRandomAccessReadDevice, typename MutableBufferSequence,
@@ -391,18 +410,10 @@ async_read_at(AsyncRandomAccessReadDevice& d,
uint64_t offset, const MutableBufferSequence& buffers,
BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
{
- // If you get an error on the following line it means that your handler does
- // not meet the documented type requirements for a ReadHandler.
- BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
-
- async_completion<ReadHandler,
- void (boost::system::error_code, std::size_t)> init(handler);
-
- detail::start_read_at_buffer_sequence_op(d, offset, buffers,
- boost::asio::buffer_sequence_begin(buffers), transfer_all(),
- init.completion_handler);
-
- return init.result.get();
+ return async_initiate<ReadHandler,
+ void (boost::system::error_code, std::size_t)>(
+ detail::initiate_async_read_at_buffer_sequence(),
+ handler, &d, offset, buffers, transfer_all());
}
#if !defined(BOOST_ASIO_NO_EXTENSIONS)
@@ -418,7 +429,7 @@ namespace detail
public:
read_at_streambuf_op(AsyncRandomAccessReadDevice& device,
uint64_t offset, basic_streambuf<Allocator>& streambuf,
- CompletionCondition completion_condition, ReadHandler& handler)
+ CompletionCondition& completion_condition, ReadHandler& handler)
: detail::base_from_completion_cond<
CompletionCondition>(completion_condition),
device_(device),
@@ -443,7 +454,9 @@ namespace detail
}
read_at_streambuf_op(read_at_streambuf_op&& other)
- : detail::base_from_completion_cond<CompletionCondition>(other),
+ : detail::base_from_completion_cond<CompletionCondition>(
+ BOOST_ASIO_MOVE_CAST(detail::base_from_completion_cond<
+ CompletionCondition>)(other)),
device_(other.device_),
offset_(other.offset_),
streambuf_(other.streambuf_),
@@ -540,6 +553,28 @@ namespace detail
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
}
+
+ struct initiate_async_read_at_streambuf
+ {
+ template <typename ReadHandler, typename AsyncRandomAccessReadDevice,
+ typename Allocator, typename CompletionCondition>
+ void operator()(BOOST_ASIO_MOVE_ARG(ReadHandler) handler,
+ AsyncRandomAccessReadDevice* d, uint64_t offset,
+ basic_streambuf<Allocator>* b,
+ BOOST_ASIO_MOVE_ARG(CompletionCondition) completion_cond) const
+ {
+ // If you get an error on the following line it means that your handler
+ // does not meet the documented type requirements for a ReadHandler.
+ BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
+
+ non_const_lvalue<ReadHandler> handler2(handler);
+ non_const_lvalue<CompletionCondition> completion_cond2(completion_cond);
+ read_at_streambuf_op<AsyncRandomAccessReadDevice, Allocator,
+ CompletionCondition, typename decay<ReadHandler>::type>(
+ *d, offset, *b, completion_cond2.value, handler2.value)(
+ boost::system::error_code(), 0, 1);
+ }
+ };
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
@@ -591,20 +626,10 @@ async_read_at(AsyncRandomAccessReadDevice& d,
CompletionCondition completion_condition,
BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
{
- // If you get an error on the following line it means that your handler does
- // not meet the documented type requirements for a ReadHandler.
- BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
-
- async_completion<ReadHandler,
- void (boost::system::error_code, std::size_t)> init(handler);
-
- detail::read_at_streambuf_op<AsyncRandomAccessReadDevice, Allocator,
- CompletionCondition, BOOST_ASIO_HANDLER_TYPE(ReadHandler,
- void (boost::system::error_code, std::size_t))>(
- d, offset, b, completion_condition, init.completion_handler)(
- boost::system::error_code(), 0, 1);
-
- return init.result.get();
+ return async_initiate<ReadHandler,
+ void (boost::system::error_code, std::size_t)>(
+ detail::initiate_async_read_at_streambuf(), handler, &d, offset,
+ &b, BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition));
}
template <typename AsyncRandomAccessReadDevice, typename Allocator,
@@ -615,20 +640,10 @@ async_read_at(AsyncRandomAccessReadDevice& d,
uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
{
- // If you get an error on the following line it means that your handler does
- // not meet the documented type requirements for a ReadHandler.
- BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
-
- async_completion<ReadHandler,
- void (boost::system::error_code, std::size_t)> init(handler);
-
- detail::read_at_streambuf_op<AsyncRandomAccessReadDevice, Allocator,
- detail::transfer_all_t, BOOST_ASIO_HANDLER_TYPE(ReadHandler,
- void (boost::system::error_code, std::size_t))>(
- d, offset, b, transfer_all(), init.completion_handler)(
- boost::system::error_code(), 0, 1);
-
- return init.result.get();
+ return async_initiate<ReadHandler,
+ void (boost::system::error_code, std::size_t)>(
+ detail::initiate_async_read_at_streambuf(),
+ handler, &d, offset, &b, transfer_all());
}
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)