File indexing completed on 2025-01-18 09:29:06
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 #if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) \
0069 && defined(BOOST_ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
0070 typename Clock = boost::posix_time::ptime,
0071 typename WaitTraits = time_traits<Clock>>
0072 #else
0073
0074 typename Clock = chrono::steady_clock,
0075 typename WaitTraits = wait_traits<Clock>>
0076 #endif
0077
0078 class basic_socket_iostream;
0079
0080 #endif
0081
0082
0083 #if defined(GENERATING_DOCUMENTATION)
0084 template <typename Protocol,
0085 typename Clock = chrono::steady_clock,
0086 typename WaitTraits = wait_traits<Clock>>
0087 #else
0088 template <typename Protocol, typename Clock, typename WaitTraits>
0089 #endif
0090 class basic_socket_iostream
0091 : private detail::socket_iostream_base<Protocol, Clock, WaitTraits>,
0092 public std::basic_iostream<char>
0093 {
0094 private:
0095
0096
0097 #if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) \
0098 && defined(BOOST_ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
0099 typedef WaitTraits traits_helper;
0100 #else
0101
0102 typedef detail::chrono_time_traits<Clock, WaitTraits> traits_helper;
0103 #endif
0104
0105
0106 public:
0107
0108 typedef Protocol protocol_type;
0109
0110
0111 typedef typename Protocol::endpoint endpoint_type;
0112
0113
0114 typedef Clock clock_type;
0115
0116 #if defined(GENERATING_DOCUMENTATION)
0117
0118 typedef typename WaitTraits::time_type time_type;
0119
0120
0121 typedef typename WaitTraits::time_point time_point;
0122
0123
0124 typedef typename WaitTraits::duration_type duration_type;
0125
0126
0127 typedef typename WaitTraits::duration duration;
0128 #else
0129 # if !defined(BOOST_ASIO_NO_DEPRECATED)
0130 typedef typename traits_helper::time_type time_type;
0131 typedef typename traits_helper::duration_type duration_type;
0132 # endif
0133 typedef typename traits_helper::time_type time_point;
0134 typedef typename traits_helper::duration_type duration;
0135 #endif
0136
0137
0138 basic_socket_iostream()
0139 : std::basic_iostream<char>(
0140 &this->detail::socket_iostream_base<
0141 Protocol, Clock, WaitTraits>::streambuf_)
0142 {
0143 this->setf(std::ios_base::unitbuf);
0144 }
0145
0146
0147 explicit basic_socket_iostream(basic_stream_socket<protocol_type> s)
0148 : detail::socket_iostream_base<
0149 Protocol, Clock, WaitTraits>(std::move(s)),
0150 std::basic_iostream<char>(
0151 &this->detail::socket_iostream_base<
0152 Protocol, Clock, WaitTraits>::streambuf_)
0153 {
0154 this->setf(std::ios_base::unitbuf);
0155 }
0156
0157
0158 basic_socket_iostream(basic_socket_iostream&& other)
0159 : detail::socket_iostream_base<
0160 Protocol, Clock, WaitTraits>(std::move(other)),
0161 std::basic_iostream<char>(std::move(other))
0162 {
0163 this->set_rdbuf(&this->detail::socket_iostream_base<
0164 Protocol, Clock, WaitTraits>::streambuf_);
0165 }
0166
0167
0168 basic_socket_iostream& operator=(basic_socket_iostream&& other)
0169 {
0170 std::basic_iostream<char>::operator=(std::move(other));
0171 detail::socket_iostream_base<
0172 Protocol, Clock, WaitTraits>::operator=(std::move(other));
0173 return *this;
0174 }
0175
0176
0177
0178
0179
0180
0181
0182 template <typename... T>
0183 explicit basic_socket_iostream(T... x)
0184 : std::basic_iostream<char>(
0185 &this->detail::socket_iostream_base<
0186 Protocol, Clock, WaitTraits>::streambuf_)
0187 {
0188 this->setf(std::ios_base::unitbuf);
0189 if (rdbuf()->connect(x...) == 0)
0190 this->setstate(std::ios_base::failbit);
0191 }
0192
0193
0194
0195
0196
0197
0198
0199 template <typename... T>
0200 void connect(T... x)
0201 {
0202 if (rdbuf()->connect(x...) == 0)
0203 this->setstate(std::ios_base::failbit);
0204 }
0205
0206
0207 void close()
0208 {
0209 if (rdbuf()->close() == 0)
0210 this->setstate(std::ios_base::failbit);
0211 }
0212
0213
0214 basic_socket_streambuf<Protocol, Clock, WaitTraits>* rdbuf() const
0215 {
0216 return const_cast<basic_socket_streambuf<Protocol, Clock, WaitTraits>*>(
0217 &this->detail::socket_iostream_base<
0218 Protocol, Clock, WaitTraits>::streambuf_);
0219 }
0220
0221
0222 basic_socket<Protocol>& socket()
0223 {
0224 return rdbuf()->socket();
0225 }
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239 const boost::system::error_code& error() const
0240 {
0241 return rdbuf()->error();
0242 }
0243
0244 #if !defined(BOOST_ASIO_NO_DEPRECATED)
0245
0246
0247
0248
0249
0250 time_point expires_at() const
0251 {
0252 return rdbuf()->expires_at();
0253 }
0254 #endif
0255
0256
0257
0258
0259
0260 time_point expiry() const
0261 {
0262 return rdbuf()->expiry();
0263 }
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274 void expires_at(const time_point& expiry_time)
0275 {
0276 rdbuf()->expires_at(expiry_time);
0277 }
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288 void expires_after(const duration& expiry_time)
0289 {
0290 rdbuf()->expires_after(expiry_time);
0291 }
0292
0293 #if !defined(BOOST_ASIO_NO_DEPRECATED)
0294
0295
0296
0297
0298 duration expires_from_now() const
0299 {
0300 return rdbuf()->expires_from_now();
0301 }
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313 void expires_from_now(const duration& expiry_time)
0314 {
0315 rdbuf()->expires_from_now(expiry_time);
0316 }
0317 #endif
0318
0319 private:
0320
0321 basic_socket_iostream(const basic_socket_iostream&) = delete;
0322 basic_socket_iostream& operator=(
0323 const basic_socket_iostream&) = delete;
0324 };
0325
0326 }
0327 }
0328
0329 #include <boost/asio/detail/pop_options.hpp>
0330
0331 #endif
0332
0333 #endif