diff options
Diffstat (limited to 'boost/asio/impl/buffered_write_stream.hpp')
-rw-r--r-- | boost/asio/impl/buffered_write_stream.hpp | 109 |
1 files changed, 91 insertions, 18 deletions
diff --git a/boost/asio/impl/buffered_write_stream.hpp b/boost/asio/impl/buffered_write_stream.hpp index 22585eb6ce..baaa694538 100644 --- a/boost/asio/impl/buffered_write_stream.hpp +++ b/boost/asio/impl/buffered_write_stream.hpp @@ -15,6 +15,8 @@ # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) +#include <boost/asio/associated_allocator.hpp> +#include <boost/asio/associated_executor.hpp> #include <boost/asio/detail/handler_alloc_helpers.hpp> #include <boost/asio/detail/handler_cont_helpers.hpp> #include <boost/asio/detail/handler_invoke_helpers.hpp> @@ -53,7 +55,7 @@ namespace detail buffered_flush_handler(detail::buffered_stream_storage& storage, WriteHandler& handler) : storage_(storage), - handler_(handler) + handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(handler)) { } @@ -122,7 +124,37 @@ namespace detail boost_asio_handler_invoke_helpers::invoke( function, this_handler->handler_); } -} +} // namespace detail + +#if !defined(GENERATING_DOCUMENTATION) + +template <typename WriteHandler, typename Allocator> +struct associated_allocator< + detail::buffered_flush_handler<WriteHandler>, Allocator> +{ + typedef typename associated_allocator<WriteHandler, Allocator>::type type; + + static type get(const detail::buffered_flush_handler<WriteHandler>& h, + const Allocator& a = Allocator()) BOOST_ASIO_NOEXCEPT + { + return associated_allocator<WriteHandler, Allocator>::get(h.handler_, a); + } +}; + +template <typename WriteHandler, typename Executor> +struct associated_executor< + detail::buffered_flush_handler<WriteHandler>, Executor> +{ + typedef typename associated_executor<WriteHandler, Executor>::type type; + + static type get(const detail::buffered_flush_handler<WriteHandler>& h, + const Executor& ex = Executor()) BOOST_ASIO_NOEXCEPT + { + return associated_executor<WriteHandler, Executor>::get(h.handler_, ex); + } +}; + +#endif // !defined(GENERATING_DOCUMENTATION) template <typename Stream> template <typename WriteHandler> @@ -135,14 +167,13 @@ buffered_write_stream<Stream>::async_flush( // not meet the documented type requirements for a WriteHandler. BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check; - detail::async_result_init< - WriteHandler, void (boost::system::error_code, std::size_t)> init( - BOOST_ASIO_MOVE_CAST(WriteHandler)(handler)); + async_completion<WriteHandler, + void (boost::system::error_code, std::size_t)> init(handler); async_write(next_layer_, buffer(storage_.data(), storage_.size()), detail::buffered_flush_handler<BOOST_ASIO_HANDLER_TYPE( WriteHandler, void (boost::system::error_code, std::size_t))>( - storage_, init.handler)); + storage_, init.completion_handler)); return init.result.get(); } @@ -152,7 +183,8 @@ template <typename ConstBufferSequence> std::size_t buffered_write_stream<Stream>::write_some( const ConstBufferSequence& buffers) { - if (boost::asio::buffer_size(buffers) == 0) + using boost::asio::buffer_size; + if (buffer_size(buffers) == 0) return 0; if (storage_.size() == storage_.capacity()) @@ -168,7 +200,8 @@ std::size_t buffered_write_stream<Stream>::write_some( { ec = boost::system::error_code(); - if (boost::asio::buffer_size(buffers) == 0) + using boost::asio::buffer_size; + if (buffer_size(buffers) == 0) return 0; if (storage_.size() == storage_.capacity() && !flush(ec)) @@ -187,7 +220,7 @@ namespace detail const ConstBufferSequence& buffers, WriteHandler& handler) : storage_(storage), buffers_(buffers), - handler_(handler) + handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(handler)) { } @@ -216,9 +249,10 @@ namespace detail } else { + using boost::asio::buffer_size; std::size_t orig_size = storage_.size(); std::size_t space_avail = storage_.capacity() - orig_size; - std::size_t bytes_avail = boost::asio::buffer_size(buffers_); + std::size_t bytes_avail = buffer_size(buffers_); std::size_t length = bytes_avail < space_avail ? bytes_avail : space_avail; storage_.resize(orig_size + length); @@ -282,6 +316,44 @@ namespace detail } } // namespace detail +#if !defined(GENERATING_DOCUMENTATION) + +template <typename ConstBufferSequence, + typename WriteHandler, typename Allocator> +struct associated_allocator< + detail::buffered_write_some_handler<ConstBufferSequence, WriteHandler>, + Allocator> +{ + typedef typename associated_allocator<WriteHandler, Allocator>::type type; + + static type get( + const detail::buffered_write_some_handler< + ConstBufferSequence, WriteHandler>& h, + const Allocator& a = Allocator()) BOOST_ASIO_NOEXCEPT + { + return associated_allocator<WriteHandler, Allocator>::get(h.handler_, a); + } +}; + +template <typename ConstBufferSequence, + typename WriteHandler, typename Executor> +struct associated_executor< + detail::buffered_write_some_handler<ConstBufferSequence, WriteHandler>, + Executor> +{ + typedef typename associated_executor<WriteHandler, Executor>::type type; + + static type get( + const detail::buffered_write_some_handler< + ConstBufferSequence, WriteHandler>& h, + const Executor& ex = Executor()) BOOST_ASIO_NOEXCEPT + { + return associated_executor<WriteHandler, Executor>::get(h.handler_, ex); + } +}; + +#endif // !defined(GENERATING_DOCUMENTATION) + template <typename Stream> template <typename ConstBufferSequence, typename WriteHandler> BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler, @@ -294,25 +366,25 @@ buffered_write_stream<Stream>::async_write_some( // not meet the documented type requirements for a WriteHandler. BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check; - detail::async_result_init< - WriteHandler, void (boost::system::error_code, std::size_t)> init( - BOOST_ASIO_MOVE_CAST(WriteHandler)(handler)); + async_completion<WriteHandler, + void (boost::system::error_code, std::size_t)> init(handler); - if (boost::asio::buffer_size(buffers) == 0 + using boost::asio::buffer_size; + if (buffer_size(buffers) == 0 || storage_.size() < storage_.capacity()) { - next_layer_.async_write_some(boost::asio::const_buffers_1(0, 0), + next_layer_.async_write_some(BOOST_ASIO_CONST_BUFFER(0, 0), detail::buffered_write_some_handler< ConstBufferSequence, BOOST_ASIO_HANDLER_TYPE( WriteHandler, void (boost::system::error_code, std::size_t))>( - storage_, buffers, init.handler)); + storage_, buffers, init.completion_handler)); } else { this->async_flush(detail::buffered_write_some_handler< ConstBufferSequence, BOOST_ASIO_HANDLER_TYPE( WriteHandler, void (boost::system::error_code, std::size_t))>( - storage_, buffers, init.handler)); + storage_, buffers, init.completion_handler)); } return init.result.get(); @@ -323,9 +395,10 @@ template <typename ConstBufferSequence> std::size_t buffered_write_stream<Stream>::copy( const ConstBufferSequence& buffers) { + using boost::asio::buffer_size; std::size_t orig_size = storage_.size(); std::size_t space_avail = storage_.capacity() - orig_size; - std::size_t bytes_avail = boost::asio::buffer_size(buffers); + std::size_t bytes_avail = buffer_size(buffers); std::size_t length = bytes_avail < space_avail ? bytes_avail : space_avail; storage_.resize(orig_size + length); return boost::asio::buffer_copy( |