Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / asio / impl / write.hpp
index 9624359..1f8c74d 100644 (file)
@@ -418,12 +418,26 @@ namespace detail
           boost::system::error_code(), 0, 1);
   }
 
-  struct initiate_async_write_buffer_sequence
+  template <typename AsyncWriteStream>
+  class initiate_async_write_buffer_sequence
   {
-    template <typename WriteHandler, typename AsyncWriteStream,
-        typename ConstBufferSequence, typename CompletionCondition>
+  public:
+    typedef typename AsyncWriteStream::executor_type executor_type;
+
+    explicit initiate_async_write_buffer_sequence(AsyncWriteStream& stream)
+      : stream_(stream)
+    {
+    }
+
+    executor_type get_executor() const BOOST_ASIO_NOEXCEPT
+    {
+      return stream_.get_executor();
+    }
+
+    template <typename WriteHandler, typename ConstBufferSequence,
+        typename CompletionCondition>
     void operator()(BOOST_ASIO_MOVE_ARG(WriteHandler) handler,
-        AsyncWriteStream* s, const ConstBufferSequence& buffers,
+        const ConstBufferSequence& buffers,
         BOOST_ASIO_MOVE_ARG(CompletionCondition) completion_cond) const
     {
       // If you get an error on the following line it means that your handler
@@ -432,10 +446,13 @@ namespace detail
 
       non_const_lvalue<WriteHandler> handler2(handler);
       non_const_lvalue<CompletionCondition> completion_cond2(completion_cond);
-      start_write_buffer_sequence_op(*s, buffers,
+      start_write_buffer_sequence_op(stream_, buffers,
           boost::asio::buffer_sequence_begin(buffers),
           completion_cond2.value, handler2.value);
     }
+
+  private:
+    AsyncWriteStream& stream_;
   };
 } // namespace detail
 
@@ -481,9 +498,11 @@ struct associated_executor<
 
 #endif // !defined(GENERATING_DOCUMENTATION)
 
-template <typename AsyncWriteStream, typename ConstBufferSequence,
-  typename CompletionCondition, typename WriteHandler>
-inline BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
+template <typename AsyncWriteStream,
+    typename ConstBufferSequence, typename CompletionCondition,
+    BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
+      std::size_t)) WriteHandler>
+inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
     void (boost::system::error_code, std::size_t))
 async_write(AsyncWriteStream& s, const ConstBufferSequence& buffers,
     CompletionCondition completion_condition,
@@ -494,13 +513,15 @@ async_write(AsyncWriteStream& s, const ConstBufferSequence& buffers,
 {
   return async_initiate<WriteHandler,
     void (boost::system::error_code, std::size_t)>(
-      detail::initiate_async_write_buffer_sequence(), handler, &s, buffers,
+      detail::initiate_async_write_buffer_sequence<AsyncWriteStream>(s),
+      handler, buffers,
       BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition));
 }
 
 template <typename AsyncWriteStream, typename ConstBufferSequence,
-    typename WriteHandler>
-inline BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
+    BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
+      std::size_t)) WriteHandler>
+inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
     void (boost::system::error_code, std::size_t))
 async_write(AsyncWriteStream& s, const ConstBufferSequence& buffers,
     BOOST_ASIO_MOVE_ARG(WriteHandler) handler,
@@ -510,8 +531,8 @@ async_write(AsyncWriteStream& s, const ConstBufferSequence& buffers,
 {
   return async_initiate<WriteHandler,
     void (boost::system::error_code, std::size_t)>(
-      detail::initiate_async_write_buffer_sequence(),
-      handler, &s, buffers, transfer_all());
+      detail::initiate_async_write_buffer_sequence<AsyncWriteStream>(s),
+      handler, buffers, transfer_all());
 }
 
 #if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
@@ -629,12 +650,26 @@ namespace detail
         function, this_handler->handler_);
   }
 
-  struct initiate_async_write_dynbuf_v1
+  template <typename AsyncWriteStream>
+  class initiate_async_write_dynbuf_v1
   {
-    template <typename WriteHandler, typename AsyncWriteStream,
-        typename DynamicBuffer_v1, typename CompletionCondition>
+  public:
+    typedef typename AsyncWriteStream::executor_type executor_type;
+
+    explicit initiate_async_write_dynbuf_v1(AsyncWriteStream& stream)
+      : stream_(stream)
+    {
+    }
+
+    executor_type get_executor() const BOOST_ASIO_NOEXCEPT
+    {
+      return stream_.get_executor();
+    }
+
+    template <typename WriteHandler, typename DynamicBuffer_v1,
+        typename CompletionCondition>
     void operator()(BOOST_ASIO_MOVE_ARG(WriteHandler) handler,
-        AsyncWriteStream* s, BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
+        BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
         BOOST_ASIO_MOVE_ARG(CompletionCondition) completion_cond) const
     {
       // If you get an error on the following line it means that your handler
@@ -646,10 +681,13 @@ namespace detail
       write_dynbuf_v1_op<AsyncWriteStream,
         typename decay<DynamicBuffer_v1>::type,
           CompletionCondition, typename decay<WriteHandler>::type>(
-            *s, BOOST_ASIO_MOVE_CAST(DynamicBuffer_v1)(buffers),
+            stream_, BOOST_ASIO_MOVE_CAST(DynamicBuffer_v1)(buffers),
               completion_cond2.value, handler2.value)(
                 boost::system::error_code(), 0, 1);
     }
+
+  private:
+    AsyncWriteStream& stream_;
   };
 } // namespace detail
 
@@ -693,9 +731,10 @@ struct associated_executor<
 
 #endif // !defined(GENERATING_DOCUMENTATION)
 
-template <typename AsyncWriteStream,
-    typename DynamicBuffer_v1, typename WriteHandler>
-inline BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
+template <typename AsyncWriteStream, typename DynamicBuffer_v1,
+    BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
+      std::size_t)) WriteHandler>
+inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
     void (boost::system::error_code, std::size_t))
 async_write(AsyncWriteStream& s,
     BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
@@ -710,9 +749,11 @@ async_write(AsyncWriteStream& s,
       transfer_all(), BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
 }
 
-template <typename AsyncWriteStream, typename DynamicBuffer_v1,
-    typename CompletionCondition, typename WriteHandler>
-inline BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
+template <typename AsyncWriteStream,
+    typename DynamicBuffer_v1, typename CompletionCondition,
+    BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
+      std::size_t)) WriteHandler>
+inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
     void (boost::system::error_code, std::size_t))
 async_write(AsyncWriteStream& s,
     BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
@@ -725,16 +766,18 @@ async_write(AsyncWriteStream& s,
 {
   return async_initiate<WriteHandler,
     void (boost::system::error_code, std::size_t)>(
-      detail::initiate_async_write_dynbuf_v1(), handler, &s,
-      BOOST_ASIO_MOVE_CAST(DynamicBuffer_v1)(buffers),
+      detail::initiate_async_write_dynbuf_v1<AsyncWriteStream>(s),
+      handler, BOOST_ASIO_MOVE_CAST(DynamicBuffer_v1)(buffers),
       BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition));
 }
 
 #if !defined(BOOST_ASIO_NO_EXTENSIONS)
 #if !defined(BOOST_ASIO_NO_IOSTREAM)
 
-template <typename AsyncWriteStream, typename Allocator, typename WriteHandler>
-inline BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
+template <typename AsyncWriteStream, typename Allocator,
+    BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
+      std::size_t)) WriteHandler>
+inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
     void (boost::system::error_code, std::size_t))
 async_write(AsyncWriteStream& s,
     boost::asio::basic_streambuf<Allocator>& b,
@@ -744,9 +787,11 @@ async_write(AsyncWriteStream& s,
       BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
 }
 
-template <typename AsyncWriteStream, typename Allocator,
-    typename CompletionCondition, typename WriteHandler>
-inline BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
+template <typename AsyncWriteStream,
+    typename Allocator, typename CompletionCondition,
+    BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
+      std::size_t)) WriteHandler>
+inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
     void (boost::system::error_code, std::size_t))
 async_write(AsyncWriteStream& s,
     boost::asio::basic_streambuf<Allocator>& b,
@@ -875,12 +920,26 @@ namespace detail
         function, this_handler->handler_);
   }
 
-  struct initiate_async_write_dynbuf_v2
+  template <typename AsyncWriteStream>
+  class initiate_async_write_dynbuf_v2
   {
-    template <typename WriteHandler, typename AsyncWriteStream,
-        typename DynamicBuffer_v2, typename CompletionCondition>
+  public:
+    typedef typename AsyncWriteStream::executor_type executor_type;
+
+    explicit initiate_async_write_dynbuf_v2(AsyncWriteStream& stream)
+      : stream_(stream)
+    {
+    }
+
+    executor_type get_executor() const BOOST_ASIO_NOEXCEPT
+    {
+      return stream_.get_executor();
+    }
+
+    template <typename WriteHandler, typename DynamicBuffer_v2,
+        typename CompletionCondition>
     void operator()(BOOST_ASIO_MOVE_ARG(WriteHandler) handler,
-        AsyncWriteStream* s, BOOST_ASIO_MOVE_ARG(DynamicBuffer_v2) buffers,
+        BOOST_ASIO_MOVE_ARG(DynamicBuffer_v2) buffers,
         BOOST_ASIO_MOVE_ARG(CompletionCondition) completion_cond) const
     {
       // If you get an error on the following line it means that your handler
@@ -892,10 +951,13 @@ namespace detail
       write_dynbuf_v2_op<AsyncWriteStream,
         typename decay<DynamicBuffer_v2>::type,
           CompletionCondition, typename decay<WriteHandler>::type>(
-            *s, BOOST_ASIO_MOVE_CAST(DynamicBuffer_v2)(buffers),
+            stream_, BOOST_ASIO_MOVE_CAST(DynamicBuffer_v2)(buffers),
               completion_cond2.value, handler2.value)(
                 boost::system::error_code(), 0, 1);
     }
+
+  private:
+    AsyncWriteStream& stream_;
   };
 } // namespace detail
 
@@ -939,9 +1001,10 @@ struct associated_executor<
 
 #endif // !defined(GENERATING_DOCUMENTATION)
 
-template <typename AsyncWriteStream,
-    typename DynamicBuffer_v2, typename WriteHandler>
-inline BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
+template <typename AsyncWriteStream, typename DynamicBuffer_v2,
+    BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
+      std::size_t)) WriteHandler>
+inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
     void (boost::system::error_code, std::size_t))
 async_write(AsyncWriteStream& s, DynamicBuffer_v2 buffers,
     BOOST_ASIO_MOVE_ARG(WriteHandler) handler,
@@ -954,9 +1017,11 @@ async_write(AsyncWriteStream& s, DynamicBuffer_v2 buffers,
       transfer_all(), BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
 }
 
-template <typename AsyncWriteStream, typename DynamicBuffer_v2,
-    typename CompletionCondition, typename WriteHandler>
-inline BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
+template <typename AsyncWriteStream,
+    typename DynamicBuffer_v2, typename CompletionCondition,
+    BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
+      std::size_t)) WriteHandler>
+inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
     void (boost::system::error_code, std::size_t))
 async_write(AsyncWriteStream& s, DynamicBuffer_v2 buffers,
     CompletionCondition completion_condition,
@@ -967,8 +1032,8 @@ async_write(AsyncWriteStream& s, DynamicBuffer_v2 buffers,
 {
   return async_initiate<WriteHandler,
     void (boost::system::error_code, std::size_t)>(
-      detail::initiate_async_write_dynbuf_v2(), handler, &s,
-      BOOST_ASIO_MOVE_CAST(DynamicBuffer_v2)(buffers),
+      detail::initiate_async_write_dynbuf_v2<AsyncWriteStream>(s),
+      handler, BOOST_ASIO_MOVE_CAST(DynamicBuffer_v2)(buffers),
       BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition));
 }