/// The type of the executor associated with the object.
typedef Executor executor_type;
+ /// Rebinds the handle type to another executor.
+ template <typename Executor1>
+ struct rebind_executor
+ {
+ /// The handle type when rebound to the specified executor.
+ typedef basic_stream_handle<Executor1> other;
+ };
+
/// The native representation of a handle.
#if defined(GENERATING_DOCUMENTATION)
typedef implementation_defined native_handle_type;
* buffers in one go, and how to use it with arrays, boost::array or
* std::vector.
*/
- template <typename ConstBufferSequence, typename WriteHandler>
- BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
+ template <typename ConstBufferSequence,
+ BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
+ std::size_t)) WriteHandler
+ BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
+ BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
void (boost::system::error_code, std::size_t))
async_write_some(const ConstBufferSequence& buffers,
- BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
+ BOOST_ASIO_MOVE_ARG(WriteHandler) handler
+ BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
{
- // If you get an error on the following line it means that your handler does
- // not meet the documented type requirements for a WriteHandler.
- BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
-
- boost::asio::async_completion<WriteHandler,
- void (boost::system::error_code, std::size_t)> init(handler);
-
- this->impl_.get_service().async_write_some(
- this->impl_.get_implementation(),
- buffers, init.completion_handler,
- this->impl_.get_implementation_executor());
-
- return init.result.get();
+ return async_initiate<WriteHandler,
+ void (boost::system::error_code, std::size_t)>(
+ initiate_async_write_some(this), handler, buffers);
}
/// Read some data from the handle.
* buffers in one go, and how to use it with arrays, boost::array or
* std::vector.
*/
- template <typename MutableBufferSequence, typename ReadHandler>
- BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
+ template <typename MutableBufferSequence,
+ BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
+ std::size_t)) ReadHandler
+ BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
+ BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ReadHandler,
void (boost::system::error_code, std::size_t))
async_read_some(const MutableBufferSequence& buffers,
- BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
+ BOOST_ASIO_MOVE_ARG(ReadHandler) handler
+ BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
{
- // 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;
+ return async_initiate<ReadHandler,
+ void (boost::system::error_code, std::size_t)>(
+ initiate_async_read_some(this), handler, buffers);
+ }
+
+private:
+ class initiate_async_write_some
+ {
+ public:
+ typedef Executor executor_type;
- boost::asio::async_completion<ReadHandler,
- void (boost::system::error_code, std::size_t)> init(handler);
+ explicit initiate_async_write_some(basic_stream_handle* self)
+ : self_(self)
+ {
+ }
- this->impl_.get_service().async_read_some(
- this->impl_.get_implementation(),
- buffers, init.completion_handler,
- this->impl_.get_implementation_executor());
+ executor_type get_executor() const BOOST_ASIO_NOEXCEPT
+ {
+ return self_->get_executor();
+ }
- return init.result.get();
- }
+ template <typename WriteHandler, typename ConstBufferSequence>
+ void operator()(BOOST_ASIO_MOVE_ARG(WriteHandler) handler,
+ const ConstBufferSequence& buffers) const
+ {
+ // If you get an error on the following line it means that your handler
+ // does not meet the documented type requirements for a WriteHandler.
+ BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
+
+ detail::non_const_lvalue<WriteHandler> handler2(handler);
+ self_->impl_.get_service().async_write_some(
+ self_->impl_.get_implementation(), buffers, handler2.value,
+ self_->impl_.get_implementation_executor());
+ }
+
+ private:
+ basic_stream_handle* self_;
+ };
+
+ class initiate_async_read_some
+ {
+ public:
+ typedef Executor executor_type;
+
+ explicit initiate_async_read_some(basic_stream_handle* self)
+ : self_(self)
+ {
+ }
+
+ executor_type get_executor() const BOOST_ASIO_NOEXCEPT
+ {
+ return self_->get_executor();
+ }
+
+ template <typename ReadHandler, typename MutableBufferSequence>
+ void operator()(BOOST_ASIO_MOVE_ARG(ReadHandler) handler,
+ const MutableBufferSequence& buffers) 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;
+
+ detail::non_const_lvalue<ReadHandler> handler2(handler);
+ self_->impl_.get_service().async_read_some(
+ self_->impl_.get_implementation(), buffers, handler2.value,
+ self_->impl_.get_implementation_executor());
+ }
+
+ private:
+ basic_stream_handle* self_;
+ };
};
} // namespace windows