Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef ASIO_BUFFERED_STREAM_HPP
00012 #define ASIO_BUFFERED_STREAM_HPP
00013
00014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
00015 # pragma once
00016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
00017
00018 #include "asio/detail/push_options.hpp"
00019
00020 #include "asio/detail/push_options.hpp"
00021 #include <cstddef>
00022 #include <boost/config.hpp>
00023 #include "asio/detail/pop_options.hpp"
00024
00025 #include "asio/buffered_read_stream.hpp"
00026 #include "asio/buffered_write_stream.hpp"
00027 #include "asio/buffered_stream_fwd.hpp"
00028 #include "asio/error.hpp"
00029 #include "asio/io_service.hpp"
00030 #include "asio/detail/noncopyable.hpp"
00031
00032 namespace asio {
00033
00035
00046 template <typename Stream>
00047 class buffered_stream
00048 : private noncopyable
00049 {
00050 public:
00052 typedef typename boost::remove_reference<Stream>::type next_layer_type;
00053
00055 typedef typename next_layer_type::lowest_layer_type lowest_layer_type;
00056
00058 template <typename Arg>
00059 explicit buffered_stream(Arg& a)
00060 : inner_stream_impl_(a),
00061 stream_impl_(inner_stream_impl_)
00062 {
00063 }
00064
00066 template <typename Arg>
00067 explicit buffered_stream(Arg& a, std::size_t read_buffer_size,
00068 std::size_t write_buffer_size)
00069 : inner_stream_impl_(a, write_buffer_size),
00070 stream_impl_(inner_stream_impl_, read_buffer_size)
00071 {
00072 }
00073
00075 next_layer_type& next_layer()
00076 {
00077 return stream_impl_.next_layer().next_layer();
00078 }
00079
00081 lowest_layer_type& lowest_layer()
00082 {
00083 return stream_impl_.lowest_layer();
00084 }
00085
00088 asio::io_service& io_service()
00089 {
00090 return stream_impl_.get_io_service();
00091 }
00092
00094 asio::io_service& get_io_service()
00095 {
00096 return stream_impl_.get_io_service();
00097 }
00098
00100 void close()
00101 {
00102 stream_impl_.close();
00103 }
00104
00106 asio::error_code close(asio::error_code& ec)
00107 {
00108 return stream_impl_.close(ec);
00109 }
00110
00114 std::size_t flush()
00115 {
00116 return stream_impl_.next_layer().flush();
00117 }
00118
00122 std::size_t flush(asio::error_code& ec)
00123 {
00124 return stream_impl_.next_layer().flush(ec);
00125 }
00126
00128 template <typename WriteHandler>
00129 void async_flush(WriteHandler handler)
00130 {
00131 return stream_impl_.next_layer().async_flush(handler);
00132 }
00133
00136 template <typename ConstBufferSequence>
00137 std::size_t write_some(const ConstBufferSequence& buffers)
00138 {
00139 return stream_impl_.write_some(buffers);
00140 }
00141
00144 template <typename ConstBufferSequence>
00145 std::size_t write_some(const ConstBufferSequence& buffers,
00146 asio::error_code& ec)
00147 {
00148 return stream_impl_.write_some(buffers, ec);
00149 }
00150
00153 template <typename ConstBufferSequence, typename WriteHandler>
00154 void async_write_some(const ConstBufferSequence& buffers,
00155 WriteHandler handler)
00156 {
00157 stream_impl_.async_write_some(buffers, handler);
00158 }
00159
00162 std::size_t fill()
00163 {
00164 return stream_impl_.fill();
00165 }
00166
00169 std::size_t fill(asio::error_code& ec)
00170 {
00171 return stream_impl_.fill(ec);
00172 }
00173
00175 template <typename ReadHandler>
00176 void async_fill(ReadHandler handler)
00177 {
00178 stream_impl_.async_fill(handler);
00179 }
00180
00183 template <typename MutableBufferSequence>
00184 std::size_t read_some(const MutableBufferSequence& buffers)
00185 {
00186 return stream_impl_.read_some(buffers);
00187 }
00188
00191 template <typename MutableBufferSequence>
00192 std::size_t read_some(const MutableBufferSequence& buffers,
00193 asio::error_code& ec)
00194 {
00195 return stream_impl_.read_some(buffers, ec);
00196 }
00197
00200 template <typename MutableBufferSequence, typename ReadHandler>
00201 void async_read_some(const MutableBufferSequence& buffers,
00202 ReadHandler handler)
00203 {
00204 stream_impl_.async_read_some(buffers, handler);
00205 }
00206
00209 template <typename MutableBufferSequence>
00210 std::size_t peek(const MutableBufferSequence& buffers)
00211 {
00212 return stream_impl_.peek(buffers);
00213 }
00214
00217 template <typename MutableBufferSequence>
00218 std::size_t peek(const MutableBufferSequence& buffers,
00219 asio::error_code& ec)
00220 {
00221 return stream_impl_.peek(buffers, ec);
00222 }
00223
00225 std::size_t in_avail()
00226 {
00227 return stream_impl_.in_avail();
00228 }
00229
00231 std::size_t in_avail(asio::error_code& ec)
00232 {
00233 return stream_impl_.in_avail(ec);
00234 }
00235
00236 private:
00237
00238 typedef buffered_write_stream<Stream> write_stream_type;
00239 write_stream_type inner_stream_impl_;
00240
00241
00242 typedef buffered_read_stream<write_stream_type&> read_stream_type;
00243 read_stream_type stream_impl_;
00244 };
00245
00246 }
00247
00248 #include "asio/detail/pop_options.hpp"
00249
00250 #endif // ASIO_BUFFERED_STREAM_HPP