|
||||
File indexing completed on 2025-01-18 09:29:27
0001 // 0002 // Copyright (c) 2022 Seth Heeren (sgheeren at gmail dot com) 0003 // 0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying 0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 0006 // 0007 // Official repository: https://github.com/boostorg/beast 0008 // 0009 0010 #ifndef BOOST_BEAST_CORE_BUFFERS_GENERATOR_HPP 0011 #define BOOST_BEAST_CORE_BUFFERS_GENERATOR_HPP 0012 0013 #include <boost/beast/core/detail/config.hpp> 0014 #include <boost/beast/core/detail/type_traits.hpp> 0015 #include <boost/beast/core/error.hpp> 0016 #include <boost/beast/core/stream_traits.hpp> 0017 #include <boost/asio/async_result.hpp> 0018 #include <type_traits> 0019 0020 namespace boost { 0021 namespace beast { 0022 0023 /** Determine if type satisfies the <em>BuffersGenerator</em> requirements. 0024 0025 This metafunction is used to determine if the specified type meets the 0026 requirements for a buffers generator. 0027 0028 The static member `value` will evaluate to `true` if so, `false` otherwise. 0029 0030 @tparam T a type to check 0031 */ 0032 #ifdef BOOST_BEAST_DOXYGEN 0033 template <class T> 0034 struct is_buffers_generator 0035 : integral_constant<bool, automatically_determined> 0036 { 0037 }; 0038 #else 0039 template<class T, class = void> 0040 struct is_buffers_generator 0041 : std::false_type 0042 { 0043 }; 0044 0045 template<class T> 0046 struct is_buffers_generator< 0047 T, detail::void_t<decltype( 0048 bool(std::declval<T const&>().is_done()), 0049 typename T::const_buffers_type( 0050 std::declval<T&>().prepare( 0051 std::declval<error_code&>())), 0052 std::declval<T&>().consume( 0053 std::size_t{}) 0054 )>> : std::true_type 0055 { 0056 }; 0057 #endif 0058 0059 /** Write all output from a BuffersGenerator to a stream. 0060 0061 This function is used to write all of the buffers generated 0062 by a caller-provided BuffersGenerator to a stream. The call 0063 will block until one of the following conditions is true: 0064 0065 @li A call to the generator's `is_done` returns `false`. 0066 0067 @li An error occurs. 0068 0069 This operation is implemented in terms of one or more calls 0070 to the stream's `write_some` function. 0071 0072 @param stream The stream to which the data is to be written. 0073 The type must support the <em>SyncWriteStream</em> concept. 0074 0075 @param generator The generator to use. 0076 0077 @param ec Set to the error, if any occurred. 0078 0079 @return The number of bytes written to the stream. 0080 0081 @see BuffersGenerator 0082 */ 0083 template< 0084 class SyncWriteStream, 0085 class BuffersGenerator 0086 #if ! BOOST_BEAST_DOXYGEN 0087 , typename std::enable_if<is_buffers_generator< 0088 typename std::decay<BuffersGenerator>:: 0089 type>::value>::type* = nullptr 0090 #endif 0091 > 0092 std::size_t 0093 write( 0094 SyncWriteStream& stream, 0095 BuffersGenerator&& generator, 0096 beast::error_code& ec); 0097 0098 /** Write all output from a BuffersGenerator to a stream. 0099 0100 This function is used to write all of the buffers generated 0101 by a caller-provided BuffersGenerator to a stream. The call 0102 will block until one of the following conditions is true: 0103 0104 @li A call to the generator's `is_done` returns `false`. 0105 0106 @li An error occurs. 0107 0108 This operation is implemented in terms of one or more calls 0109 to the stream's `write_some` function. 0110 0111 @param stream The stream to which the data is to be written. 0112 The type must support the <em>SyncWriteStream</em> concept. 0113 0114 @param generator The generator to use. 0115 0116 @return The number of bytes written to the stream. 0117 0118 @throws system_error Thrown on failure. 0119 0120 @see BuffersGenerator 0121 */ 0122 template< 0123 class SyncWriteStream, 0124 class BuffersGenerator 0125 #if ! BOOST_BEAST_DOXYGEN 0126 , typename std::enable_if<is_buffers_generator< 0127 typename std::decay<BuffersGenerator>:: 0128 type>::value>::type* = nullptr 0129 #endif 0130 > 0131 std::size_t 0132 write( 0133 SyncWriteStream& stream, 0134 BuffersGenerator&& generator); 0135 0136 /** Write all output from a BuffersGenerator asynchronously to a 0137 stream. 0138 0139 This function is used to write all of the buffers generated 0140 by a caller-provided `BuffersGenerator` to a stream. The 0141 function call always returns immediately. The asynchronous 0142 operation will continue until one of the following 0143 conditions is true: 0144 0145 @li A call to the generator's `is_done` returns `false`. 0146 0147 @li An error occurs. 0148 0149 This operation is implemented in terms of zero or more calls 0150 to the stream's `async_write_some` function, and is known as 0151 a <em>composed operation</em>. The program must ensure that 0152 the stream performs no other writes until this operation 0153 completes. 0154 0155 @param stream The stream to which the data is to be written. 0156 The type must support the <em>SyncWriteStream</em> concept. 0157 0158 @param generator The generator to use. 0159 0160 @param token The completion handler to invoke when the 0161 operation completes. The implementation takes ownership of 0162 the handler by performing a decay-copy. The equivalent 0163 function signature of the handler must be: 0164 @code 0165 void handler( 0166 error_code const& error, // result of operation 0167 std::size_t bytes_transferred // the number of bytes written to the stream 0168 ); 0169 @endcode 0170 If the handler has an associated immediate executor, 0171 an immediate completion will be dispatched to it. 0172 Otherwise, the handler will not be invoked from within 0173 this function. Invocation of the handler will be performed in a 0174 manner equivalent to using `net::post`. 0175 0176 @see BuffersGenerator 0177 */ 0178 template< 0179 class AsyncWriteStream, 0180 class BuffersGenerator, 0181 BOOST_BEAST_ASYNC_TPARAM2 CompletionToken 0182 = net::default_completion_token_t<executor_type<AsyncWriteStream>> 0183 #if !BOOST_BEAST_DOXYGEN 0184 , typename std::enable_if<is_buffers_generator< 0185 BuffersGenerator>::value>::type* = nullptr 0186 #endif 0187 > 0188 BOOST_BEAST_ASYNC_RESULT2(CompletionToken) 0189 async_write( 0190 AsyncWriteStream& stream, 0191 BuffersGenerator generator, 0192 CompletionToken&& token 0193 = net::default_completion_token_t<executor_type<AsyncWriteStream>>{}); 0194 0195 } // beast 0196 } // boost 0197 0198 #include <boost/beast/core/impl/buffers_generator.hpp> 0199 0200 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |