|
||||
File indexing completed on 2025-01-18 09:29:24
0001 // 0002 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco 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_DETAIL_READ_HPP 0011 #define BOOST_BEAST_DETAIL_READ_HPP 0012 0013 #include <boost/beast/core/detail/config.hpp> 0014 #include <boost/beast/core/error.hpp> 0015 #include <boost/beast/core/stream_traits.hpp> 0016 #include <boost/beast/core/detail/is_invocable.hpp> 0017 #include <boost/asio/async_result.hpp> 0018 #include <cstdlib> 0019 0020 namespace boost { 0021 namespace beast { 0022 namespace detail { 0023 0024 //------------------------------------------------------------------------------ 0025 0026 /** Read data into a dynamic buffer from a stream until a condition is met. 0027 0028 This function is used to read from a stream into a dynamic buffer until 0029 a condition is met. The call will block until one of the following is true: 0030 0031 @li The specified dynamic buffer sequence is full (that is, it has 0032 reached its currently configured maximum size). 0033 0034 @li The `completion_condition` function object returns 0. 0035 0036 This operation is implemented in terms of zero or more calls to the 0037 stream's `read_some` function. 0038 0039 @param stream The stream from which the data is to be read. The type 0040 must support the <em>SyncReadStream</em> requirements. 0041 0042 @param buffer The dynamic buffer sequence into which the data will be read. 0043 0044 @param completion_condition The function object to be called to determine 0045 whether the read operation is complete. The function object must be invocable 0046 with this signature: 0047 @code 0048 std::size_t 0049 completion_condition( 0050 // Modifiable result of latest read_some operation. 0051 error_code& ec, 0052 0053 // Number of bytes transferred so far. 0054 std::size_t bytes_transferred 0055 0056 // The dynamic buffer used to store the bytes read 0057 DynamicBuffer& buffer 0058 ); 0059 @endcode 0060 A non-zero return value indicates the maximum number of bytes to be read on 0061 the next call to the stream's `read_some` function. A return value of 0 0062 from the completion condition indicates that the read operation is complete; 0063 in this case the optionally modifiable error passed to the completion 0064 condition will be delivered to the caller as an exception. 0065 0066 @returns The number of bytes transferred from the stream. 0067 0068 @throws net::system_error Thrown on failure. 0069 */ 0070 template< 0071 class SyncReadStream, 0072 class DynamicBuffer, 0073 class CompletionCondition 0074 #if ! BOOST_BEAST_DOXYGEN 0075 , class = typename std::enable_if< 0076 is_sync_read_stream<SyncReadStream>::value && 0077 net::is_dynamic_buffer<DynamicBuffer>::value && 0078 detail::is_invocable<CompletionCondition, 0079 void(error_code&, std::size_t, DynamicBuffer&)>::value 0080 >::type 0081 #endif 0082 > 0083 std::size_t 0084 read( 0085 SyncReadStream& stream, 0086 DynamicBuffer& buffer, 0087 CompletionCondition completion_condition); 0088 0089 /** Read data into a dynamic buffer from a stream until a condition is met. 0090 0091 This function is used to read from a stream into a dynamic buffer until 0092 a condition is met. The call will block until one of the following is true: 0093 0094 @li The specified dynamic buffer sequence is full (that is, it has 0095 reached its currently configured maximum size). 0096 0097 @li The `completion_condition` function object returns 0. 0098 0099 This operation is implemented in terms of zero or more calls to the 0100 stream's `read_some` function. 0101 0102 @param stream The stream from which the data is to be read. The type 0103 must support the <em>SyncReadStream</em> requirements. 0104 0105 @param buffer The dynamic buffer sequence into which the data will be read. 0106 0107 @param completion_condition The function object to be called to determine 0108 whether the read operation is complete. The function object must be invocable 0109 with this signature: 0110 @code 0111 std::size_t 0112 completion_condition( 0113 // Modifiable result of latest read_some operation. 0114 error_code& ec, 0115 0116 // Number of bytes transferred so far. 0117 std::size_t bytes_transferred 0118 0119 // The dynamic buffer used to store the bytes read 0120 DynamicBuffer& buffer 0121 ); 0122 @endcode 0123 A non-zero return value indicates the maximum number of bytes to be read on 0124 the next call to the stream's `read_some` function. A return value of 0 0125 from the completion condition indicates that the read operation is complete; 0126 in this case the optionally modifiable error passed to the completion 0127 condition will be delivered to the caller. 0128 0129 @returns The number of bytes transferred from the stream. 0130 */ 0131 template< 0132 class SyncReadStream, 0133 class DynamicBuffer, 0134 class CompletionCondition 0135 #if ! BOOST_BEAST_DOXYGEN 0136 , class = typename std::enable_if< 0137 is_sync_read_stream<SyncReadStream>::value && 0138 net::is_dynamic_buffer<DynamicBuffer>::value && 0139 detail::is_invocable<CompletionCondition, 0140 void(error_code&, std::size_t, DynamicBuffer&)>::value 0141 >::type 0142 #endif 0143 > 0144 std::size_t 0145 read( 0146 SyncReadStream& stream, 0147 DynamicBuffer& buffer, 0148 CompletionCondition completion_condition, 0149 error_code& ec); 0150 0151 /** Asynchronously read data into a dynamic buffer from a stream until a condition is met. 0152 0153 This function is used to asynchronously read from a stream into a dynamic 0154 buffer until a condition is met. The function call always returns immediately. 0155 The asynchronous operation will continue until one of the following is true: 0156 0157 @li The specified dynamic buffer sequence is full (that is, it has 0158 reached its currently configured maximum size). 0159 0160 @li The `completion_condition` function object returns 0. 0161 0162 This operation is implemented in terms of zero or more calls to the stream's 0163 `async_read_some` function, and is known as a <em>composed operation</em>. The 0164 program must ensure that the stream performs no other read operations (such 0165 as `async_read`, the stream's `async_read_some` function, or any other composed 0166 operations that perform reads) until this operation completes. 0167 0168 @param stream The stream from which the data is to be read. The type must 0169 support the <em>AsyncReadStream</em> requirements. 0170 0171 @param buffer The dynamic buffer sequence into which the data will be read. 0172 Ownership of the object is retained by the caller, which must guarantee 0173 that it remains valid until the handler is called. 0174 0175 @param completion_condition The function object to be called to determine 0176 whether the read operation is complete. The function object must be invocable 0177 with this signature: 0178 @code 0179 std::size_t 0180 completion_condition( 0181 // Modifiable result of latest async_read_some operation. 0182 error_code& ec, 0183 0184 // Number of bytes transferred so far. 0185 std::size_t bytes_transferred, 0186 0187 // The dynamic buffer used to store the bytes read 0188 DynamicBuffer& buffer 0189 ); 0190 @endcode 0191 A non-zero return value indicates the maximum number of bytes to be read on 0192 the next call to the stream's `async_read_some` function. A return value of 0 0193 from the completion condition indicates that the read operation is complete; 0194 in this case the optionally modifiable error passed to the completion 0195 condition will be delivered to the completion handler. 0196 0197 @param handler The completion handler to invoke when the operation 0198 completes. The implementation takes ownership of the handler by 0199 performing a decay-copy. The equivalent function signature of 0200 the handler must be: 0201 @code 0202 void 0203 handler( 0204 error_code const& ec, // Result of operation. 0205 0206 std::size_t bytes_transferred // Number of bytes copied into 0207 // the dynamic buffer. If an error 0208 // occurred, this will be the number 0209 // of bytes successfully transferred 0210 // prior to the error. 0211 ); 0212 @endcode 0213 If the handler has an associated immediate executor, 0214 an immediate completion will be dispatched to it. 0215 Otherwise, the handler will not be invoked from within 0216 this function. Invocation of the handler will be performed in a 0217 manner equivalent to using `net::post`. 0218 */ 0219 template< 0220 class AsyncReadStream, 0221 class DynamicBuffer, 0222 class CompletionCondition, 0223 BOOST_BEAST_ASYNC_TPARAM2 ReadHandler 0224 #if ! BOOST_BEAST_DOXYGEN 0225 , class = typename std::enable_if< 0226 is_async_read_stream<AsyncReadStream>::value && 0227 net::is_dynamic_buffer<DynamicBuffer>::value && 0228 detail::is_invocable<CompletionCondition, 0229 void(error_code&, std::size_t, DynamicBuffer&)>::value 0230 >::type 0231 #endif 0232 > 0233 BOOST_BEAST_ASYNC_RESULT2(ReadHandler) 0234 async_read( 0235 AsyncReadStream& stream, 0236 DynamicBuffer& buffer, 0237 CompletionCondition&& completion_condition, 0238 ReadHandler&& handler); 0239 0240 } // detail 0241 } // beast 0242 } // boost 0243 0244 #include <boost/beast/core/detail/impl/read.hpp> 0245 0246 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |