File indexing completed on 2025-09-15 08:29:55
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_BASIC_SOCKET_IOSTREAM_HPP
0012 #define BOOST_ASIO_BASIC_SOCKET_IOSTREAM_HPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/config.hpp>
0019
0020 #if !defined(BOOST_ASIO_NO_IOSTREAM)
0021
0022 #include <istream>
0023 #include <ostream>
0024 #include <boost/asio/basic_socket_streambuf.hpp>
0025
0026 #include <boost/asio/detail/push_options.hpp>
0027
0028 namespace boost {
0029 namespace asio {
0030 namespace detail {
0031
0032
0033
0034 template <typename Protocol, typename Clock, typename WaitTraits>
0035 class socket_iostream_base
0036 {
0037 protected:
0038 socket_iostream_base()
0039 {
0040 }
0041
0042 socket_iostream_base(socket_iostream_base&& other)
0043 : streambuf_(std::move(other.streambuf_))
0044 {
0045 }
0046
0047 socket_iostream_base(basic_stream_socket<Protocol> s)
0048 : streambuf_(std::move(s))
0049 {
0050 }
0051
0052 socket_iostream_base& operator=(socket_iostream_base&& other)
0053 {
0054 streambuf_ = std::move(other.streambuf_);
0055 return *this;
0056 }
0057
0058 basic_socket_streambuf<Protocol, Clock, WaitTraits> streambuf_;
0059 };
0060
0061 }
0062
0063 #if !defined(BOOST_ASIO_BASIC_SOCKET_IOSTREAM_FWD_DECL)
0064 #define BOOST_ASIO_BASIC_SOCKET_IOSTREAM_FWD_DECL
0065
0066
0067 template <typename Protocol,
0068 typename Clock = chrono::steady_clock,
0069 typename WaitTraits = wait_traits<Clock>>
0070 class basic_socket_iostream;
0071
0072 #endif
0073
0074
0075 #if defined(GENERATING_DOCUMENTATION)
0076 template <typename Protocol,
0077 typename Clock = chrono::steady_clock,
0078 typename WaitTraits = wait_traits<Clock>>
0079 #else
0080 template <typename Protocol, typename Clock, typename WaitTraits>
0081 #endif
0082 class basic_socket_iostream
0083 : private detail::socket_iostream_base<Protocol, Clock, WaitTraits>,
0084 public std::basic_iostream<char>
0085 {
0086 private:
0087 typedef detail::chrono_time_traits<Clock, WaitTraits> traits_helper;
0088
0089 public:
0090
0091 typedef Protocol protocol_type;
0092
0093
0094 typedef typename Protocol::endpoint endpoint_type;
0095
0096
0097 typedef Clock clock_type;
0098
0099 #if defined(GENERATING_DOCUMENTATION)
0100
0101 typedef typename WaitTraits::time_point time_point;
0102
0103
0104 typedef typename WaitTraits::duration duration;
0105 #else
0106 typedef typename traits_helper::time_type time_point;
0107 typedef typename traits_helper::duration_type duration;
0108 #endif
0109
0110
0111 basic_socket_iostream()
0112 : std::basic_iostream<char>(
0113 &this->detail::socket_iostream_base<
0114 Protocol, Clock, WaitTraits>::streambuf_)
0115 {
0116 this->setf(std::ios_base::unitbuf);
0117 }
0118
0119
0120 explicit basic_socket_iostream(basic_stream_socket<protocol_type> s)
0121 : detail::socket_iostream_base<
0122 Protocol, Clock, WaitTraits>(std::move(s)),
0123 std::basic_iostream<char>(
0124 &this->detail::socket_iostream_base<
0125 Protocol, Clock, WaitTraits>::streambuf_)
0126 {
0127 this->setf(std::ios_base::unitbuf);
0128 }
0129
0130
0131 basic_socket_iostream(basic_socket_iostream&& other)
0132 : detail::socket_iostream_base<
0133 Protocol, Clock, WaitTraits>(std::move(other)),
0134 std::basic_iostream<char>(std::move(other))
0135 {
0136 this->set_rdbuf(&this->detail::socket_iostream_base<
0137 Protocol, Clock, WaitTraits>::streambuf_);
0138 }
0139
0140
0141 basic_socket_iostream& operator=(basic_socket_iostream&& other)
0142 {
0143 std::basic_iostream<char>::operator=(std::move(other));
0144 detail::socket_iostream_base<
0145 Protocol, Clock, WaitTraits>::operator=(std::move(other));
0146 return *this;
0147 }
0148
0149
0150
0151
0152
0153
0154
0155 template <typename... T>
0156 explicit basic_socket_iostream(T... x)
0157 : std::basic_iostream<char>(
0158 &this->detail::socket_iostream_base<
0159 Protocol, Clock, WaitTraits>::streambuf_)
0160 {
0161 this->setf(std::ios_base::unitbuf);
0162 if (rdbuf()->connect(x...) == 0)
0163 this->setstate(std::ios_base::failbit);
0164 }
0165
0166
0167
0168
0169
0170
0171
0172 template <typename... T>
0173 void connect(T... x)
0174 {
0175 if (rdbuf()->connect(x...) == 0)
0176 this->setstate(std::ios_base::failbit);
0177 }
0178
0179
0180 void close()
0181 {
0182 if (rdbuf()->close() == 0)
0183 this->setstate(std::ios_base::failbit);
0184 }
0185
0186
0187 basic_socket_streambuf<Protocol, Clock, WaitTraits>* rdbuf() const
0188 {
0189 return const_cast<basic_socket_streambuf<Protocol, Clock, WaitTraits>*>(
0190 &this->detail::socket_iostream_base<
0191 Protocol, Clock, WaitTraits>::streambuf_);
0192 }
0193
0194
0195 basic_socket<Protocol>& socket()
0196 {
0197 return rdbuf()->socket();
0198 }
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212 const boost::system::error_code& error() const
0213 {
0214 return rdbuf()->error();
0215 }
0216
0217
0218
0219
0220
0221 time_point expiry() const
0222 {
0223 return rdbuf()->expiry();
0224 }
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235 void expires_at(const time_point& expiry_time)
0236 {
0237 rdbuf()->expires_at(expiry_time);
0238 }
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249 void expires_after(const duration& expiry_time)
0250 {
0251 rdbuf()->expires_after(expiry_time);
0252 }
0253
0254 private:
0255
0256 basic_socket_iostream(const basic_socket_iostream&) = delete;
0257 basic_socket_iostream& operator=(
0258 const basic_socket_iostream&) = delete;
0259 };
0260
0261 }
0262 }
0263
0264 #include <boost/asio/detail/pop_options.hpp>
0265
0266 #endif
0267
0268 #endif