File indexing completed on 2025-01-30 09:33:43
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_BUFFERED_READ_STREAM_HPP
0012 #define BOOST_ASIO_BUFFERED_READ_STREAM_HPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/config.hpp>
0019 #include <cstddef>
0020 #include <boost/asio/async_result.hpp>
0021 #include <boost/asio/buffered_read_stream_fwd.hpp>
0022 #include <boost/asio/buffer.hpp>
0023 #include <boost/asio/detail/bind_handler.hpp>
0024 #include <boost/asio/detail/buffer_resize_guard.hpp>
0025 #include <boost/asio/detail/buffered_stream_storage.hpp>
0026 #include <boost/asio/detail/noncopyable.hpp>
0027 #include <boost/asio/detail/type_traits.hpp>
0028 #include <boost/asio/error.hpp>
0029
0030 #include <boost/asio/detail/push_options.hpp>
0031
0032 namespace boost {
0033 namespace asio {
0034 namespace detail {
0035
0036 template <typename> class initiate_async_buffered_fill;
0037 template <typename> class initiate_async_buffered_read_some;
0038
0039 }
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053 template <typename Stream>
0054 class buffered_read_stream
0055 : private noncopyable
0056 {
0057 public:
0058
0059 typedef remove_reference_t<Stream> next_layer_type;
0060
0061
0062 typedef typename next_layer_type::lowest_layer_type lowest_layer_type;
0063
0064
0065 typedef typename lowest_layer_type::executor_type executor_type;
0066
0067 #if defined(GENERATING_DOCUMENTATION)
0068
0069 static const std::size_t default_buffer_size = implementation_defined;
0070 #else
0071 BOOST_ASIO_STATIC_CONSTANT(std::size_t, default_buffer_size = 1024);
0072 #endif
0073
0074
0075 template <typename Arg>
0076 explicit buffered_read_stream(Arg&& a)
0077 : next_layer_(static_cast<Arg&&>(a)),
0078 storage_(default_buffer_size)
0079 {
0080 }
0081
0082
0083 template <typename Arg>
0084 buffered_read_stream(Arg&& a,
0085 std::size_t buffer_size)
0086 : next_layer_(static_cast<Arg&&>(a)),
0087 storage_(buffer_size)
0088 {
0089 }
0090
0091
0092 next_layer_type& next_layer()
0093 {
0094 return next_layer_;
0095 }
0096
0097
0098 lowest_layer_type& lowest_layer()
0099 {
0100 return next_layer_.lowest_layer();
0101 }
0102
0103
0104 const lowest_layer_type& lowest_layer() const
0105 {
0106 return next_layer_.lowest_layer();
0107 }
0108
0109
0110 executor_type get_executor() noexcept
0111 {
0112 return next_layer_.lowest_layer().get_executor();
0113 }
0114
0115
0116 void close()
0117 {
0118 next_layer_.close();
0119 }
0120
0121
0122 BOOST_ASIO_SYNC_OP_VOID close(boost::system::error_code& ec)
0123 {
0124 next_layer_.close(ec);
0125 BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
0126 }
0127
0128
0129
0130 template <typename ConstBufferSequence>
0131 std::size_t write_some(const ConstBufferSequence& buffers)
0132 {
0133 return next_layer_.write_some(buffers);
0134 }
0135
0136
0137
0138 template <typename ConstBufferSequence>
0139 std::size_t write_some(const ConstBufferSequence& buffers,
0140 boost::system::error_code& ec)
0141 {
0142 return next_layer_.write_some(buffers, ec);
0143 }
0144
0145
0146
0147
0148
0149
0150
0151 template <typename ConstBufferSequence,
0152 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
0153 std::size_t)) WriteHandler = default_completion_token_t<executor_type>>
0154 auto async_write_some(const ConstBufferSequence& buffers,
0155 WriteHandler&& handler = default_completion_token_t<executor_type>())
0156 -> decltype(
0157 declval<conditional_t<true, Stream&, WriteHandler>>().async_write_some(
0158 buffers, static_cast<WriteHandler&&>(handler)))
0159 {
0160 return next_layer_.async_write_some(buffers,
0161 static_cast<WriteHandler&&>(handler));
0162 }
0163
0164
0165
0166 std::size_t fill();
0167
0168
0169
0170 std::size_t fill(boost::system::error_code& ec);
0171
0172
0173
0174
0175
0176
0177 template <
0178 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
0179 std::size_t)) ReadHandler = default_completion_token_t<executor_type>>
0180 auto async_fill(
0181 ReadHandler&& handler = default_completion_token_t<executor_type>())
0182 -> decltype(
0183 async_initiate<ReadHandler,
0184 void (boost::system::error_code, std::size_t)>(
0185 declval<detail::initiate_async_buffered_fill<Stream>>(),
0186 handler, declval<detail::buffered_stream_storage*>()));
0187
0188
0189
0190 template <typename MutableBufferSequence>
0191 std::size_t read_some(const MutableBufferSequence& buffers);
0192
0193
0194
0195 template <typename MutableBufferSequence>
0196 std::size_t read_some(const MutableBufferSequence& buffers,
0197 boost::system::error_code& ec);
0198
0199
0200
0201
0202
0203
0204
0205 template <typename MutableBufferSequence,
0206 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
0207 std::size_t)) ReadHandler = default_completion_token_t<executor_type>>
0208 auto async_read_some(const MutableBufferSequence& buffers,
0209 ReadHandler&& handler = default_completion_token_t<executor_type>())
0210 -> decltype(
0211 async_initiate<ReadHandler,
0212 void (boost::system::error_code, std::size_t)>(
0213 declval<detail::initiate_async_buffered_read_some<Stream>>(),
0214 handler, declval<detail::buffered_stream_storage*>(), buffers));
0215
0216
0217
0218 template <typename MutableBufferSequence>
0219 std::size_t peek(const MutableBufferSequence& buffers);
0220
0221
0222
0223 template <typename MutableBufferSequence>
0224 std::size_t peek(const MutableBufferSequence& buffers,
0225 boost::system::error_code& ec);
0226
0227
0228 std::size_t in_avail()
0229 {
0230 return storage_.size();
0231 }
0232
0233
0234 std::size_t in_avail(boost::system::error_code& ec)
0235 {
0236 ec = boost::system::error_code();
0237 return storage_.size();
0238 }
0239
0240 private:
0241
0242
0243 template <typename MutableBufferSequence>
0244 std::size_t copy(const MutableBufferSequence& buffers)
0245 {
0246 std::size_t bytes_copied = boost::asio::buffer_copy(
0247 buffers, storage_.data(), storage_.size());
0248 storage_.consume(bytes_copied);
0249 return bytes_copied;
0250 }
0251
0252
0253
0254
0255 template <typename MutableBufferSequence>
0256 std::size_t peek_copy(const MutableBufferSequence& buffers)
0257 {
0258 return boost::asio::buffer_copy(buffers, storage_.data(), storage_.size());
0259 }
0260
0261
0262 Stream next_layer_;
0263
0264
0265 detail::buffered_stream_storage storage_;
0266 };
0267
0268 }
0269 }
0270
0271 #include <boost/asio/detail/pop_options.hpp>
0272
0273 #include <boost/asio/impl/buffered_read_stream.hpp>
0274
0275 #endif