11 #ifndef ASIO_BASIC_SOCKET_IOSTREAM_HPP 12 #define ASIO_BASIC_SOCKET_IOSTREAM_HPP 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 18 #include "asio/detail/config.hpp" 20 #if !defined(ASIO_NO_IOSTREAM) 24 #include "asio/basic_socket_streambuf.hpp" 26 #if !defined(ASIO_HAS_VARIADIC_TEMPLATES) 28 # include "asio/detail/variadic_templates.hpp" 42 # define ASIO_PRIVATE_CTR_DEF(n) \ 43 template <ASIO_VARIADIC_TPARAMS(n)> \ 44 explicit basic_socket_iostream(ASIO_VARIADIC_BYVAL_PARAMS(n)) \ 45 : std::basic_iostream<char>( \ 46 &this->detail::socket_iostream_base< \ 47 Protocol, Clock, WaitTraits>::streambuf_) \ 49 this->setf(std::ios_base::unitbuf); \ 50 if (rdbuf()->connect(ASIO_VARIADIC_BYVAL_ARGS(n)) == 0) \ 51 this->setstate(std::ios_base::failbit); \ 64 # define ASIO_PRIVATE_CONNECT_DEF(n) \ 65 template <ASIO_VARIADIC_TPARAMS(n)> \ 66 void connect(ASIO_VARIADIC_BYVAL_PARAMS(n)) \ 68 if (rdbuf()->connect(ASIO_VARIADIC_BYVAL_ARGS(n)) == 0) \ 69 this->setstate(std::ios_base::failbit); \ 73 #endif // !defined(ASIO_HAS_VARIADIC_TEMPLATES) 75 #include "asio/detail/push_options.hpp" 82 template <
typename Protocol,
typename Clock,
typename WaitTraits>
90 #if defined(ASIO_HAS_MOVE) 92 : streambuf_(std::move(other.streambuf_))
97 : streambuf_(std::move(s))
103 streambuf_ = std::move(other.streambuf_);
106 #endif // defined(ASIO_HAS_MOVE) 113 #if !defined(ASIO_BASIC_SOCKET_IOSTREAM_FWD_DECL) 114 #define ASIO_BASIC_SOCKET_IOSTREAM_FWD_DECL 117 template <
typename Protocol,
118 #if defined(ASIO_HAS_BOOST_DATE_TIME) \ 119 && defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM) 120 typename Clock = boost::posix_time::ptime,
121 typename WaitTraits = time_traits<Clock> >
122 #else // defined(ASIO_HAS_BOOST_DATE_TIME) 124 typename Clock = chrono::steady_clock,
126 #endif // defined(ASIO_HAS_BOOST_DATE_TIME) 130 #endif // !defined(ASIO_BASIC_SOCKET_IOSTREAM_FWD_DECL) 133 #if defined(GENERATING_DOCUMENTATION) 134 template <
typename Protocol,
135 typename Clock = chrono::steady_clock,
137 #else // defined(GENERATING_DOCUMENTATION) 138 template <
typename Protocol,
typename Clock,
typename WaitTraits>
139 #endif // defined(GENERATING_DOCUMENTATION) 142 public std::basic_iostream<char>
147 #if defined(ASIO_HAS_BOOST_DATE_TIME) \ 148 && defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM) 150 #else // defined(ASIO_HAS_BOOST_DATE_TIME) 153 #endif // defined(ASIO_HAS_BOOST_DATE_TIME) 166 #if defined(GENERATING_DOCUMENTATION) 167 typedef typename WaitTraits::time_type time_type;
171 typedef typename WaitTraits::time_point time_point;
174 typedef typename WaitTraits::duration_type duration_type;
177 typedef typename WaitTraits::duration duration;
179 # if !defined(ASIO_NO_DEPRECATED) 180 typedef typename traits_helper::time_type time_type;
181 typedef typename traits_helper::duration_type duration_type;
182 # endif // !defined(ASIO_NO_DEPRECATED) 183 typedef typename traits_helper::time_type time_point;
184 typedef typename traits_helper::duration_type duration;
189 :
std::basic_iostream<char>(
190 &this->
detail::socket_iostream_base<
191 Protocol, Clock, WaitTraits>::streambuf_)
193 this->setf(std::ios_base::unitbuf);
196 #if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) 200 Protocol, Clock, WaitTraits>(std::move(s)),
201 std::basic_iostream<char>(
203 Protocol, Clock, WaitTraits>::streambuf_)
205 this->setf(std::ios_base::unitbuf);
208 #if defined(ASIO_HAS_STD_IOSTREAM_MOVE) \ 209 || defined(GENERATING_DOCUMENTATION) 213 Protocol, Clock, WaitTraits>(std::move(other)),
214 std::basic_iostream<char>(std::move(other))
217 Protocol, Clock, WaitTraits>::streambuf_);
223 std::basic_iostream<char>::operator=(std::move(other));
225 Protocol, Clock, WaitTraits>::operator=(std::move(other));
228 #endif // defined(ASIO_HAS_STD_IOSTREAM_MOVE) 230 #endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) 232 #if defined(GENERATING_DOCUMENTATION) 239 template <
typename T1, ...,
typename TN>
241 #elif defined(ASIO_HAS_VARIADIC_TEMPLATES) 242 template <
typename... T>
243 explicit basic_socket_iostream(T... x)
244 : std::basic_iostream<char>(
246 Protocol, Clock, WaitTraits>::streambuf_)
248 this->setf(std::ios_base::unitbuf);
249 if (rdbuf()->
connect(x...) == 0)
250 this->setstate(std::ios_base::failbit);
253 ASIO_VARIADIC_GENERATE(ASIO_PRIVATE_CTR_DEF)
256 #if defined(GENERATING_DOCUMENTATION) 263 template <
typename T1, ...,
typename TN>
264 void connect(T1 t1, ..., TN tn);
265 #elif defined(ASIO_HAS_VARIADIC_TEMPLATES) 266 template <
typename... T>
269 if (rdbuf()->
connect(x...) == 0)
270 this->setstate(std::ios_base::failbit);
273 ASIO_VARIADIC_GENERATE(ASIO_PRIVATE_CONNECT_DEF)
279 if (rdbuf()->close() == 0)
280 this->setstate(std::ios_base::failbit);
288 Protocol, Clock, WaitTraits>::streambuf_);
294 return rdbuf()->socket();
311 return rdbuf()->error();
314 #if !defined(ASIO_NO_DEPRECATED) 322 return rdbuf()->expires_at();
324 #endif // !defined(ASIO_NO_DEPRECATED) 332 return rdbuf()->expiry();
346 rdbuf()->expires_at(expiry_time);
360 rdbuf()->expires_after(expiry_time);
363 #if !defined(ASIO_NO_DEPRECATED) 370 return rdbuf()->expires_from_now();
385 rdbuf()->expires_from_now(expiry_time);
387 #endif // !defined(ASIO_NO_DEPRECATED) 391 basic_socket_iostream(
const basic_socket_iostream&) ASIO_DELETED;
392 basic_socket_iostream& operator=(
393 const basic_socket_iostream&) ASIO_DELETED;
398 #include "asio/detail/pop_options.hpp" 400 #if !defined(ASIO_HAS_VARIADIC_TEMPLATES) 401 # undef ASIO_PRIVATE_CTR_DEF 402 # undef ASIO_PRIVATE_CONNECT_DEF 403 #endif // !defined(ASIO_HAS_VARIADIC_TEMPLATES) 405 #endif // !defined(ASIO_NO_IOSTREAM) 407 #endif // ASIO_BASIC_SOCKET_IOSTREAM_HPP Iostream interface for a socket.
Definition: basic_socket_iostream.hpp:128
void expires_from_now(const duration &expiry_time)
(Deprecated: Use expires_after().) Set the stream's expiry time relative to now.
Definition: basic_socket_iostream.hpp:383
Definition: blocking.hpp:208
time_point expiry() const
Get the stream's expiry time as an absolute time.
Definition: basic_socket_iostream.hpp:330
Provides stream-oriented socket functionality.
Definition: basic_stream_socket.hpp:36
const asio::error_code & error() const
Get the last error associated with the stream.
Definition: basic_socket_iostream.hpp:309
Clock clock_type
The clock type.
Definition: basic_socket_iostream.hpp:164
Definition: chrono_time_traits.hpp:34
basic_socket< Protocol > & socket()
Get a reference to the underlying socket.
Definition: basic_socket_iostream.hpp:292
Definition: awaitable.hpp:421
void expires_after(const duration &expiry_time)
Set the stream's expiry time relative to now.
Definition: basic_socket_iostream.hpp:358
void close()
Close the connection.
Definition: basic_socket_iostream.hpp:277
duration expires_from_now() const
(Deprecated: Use expiry().) Get the stream's expiry time relative to now.
Definition: basic_socket_iostream.hpp:368
void expires_at(const time_point &expiry_time)
Set the stream's expiry time as an absolute time.
Definition: basic_socket_iostream.hpp:344
Definition: basic_socket_iostream.hpp:83
Protocol::endpoint endpoint_type
The endpoint type.
Definition: basic_socket_iostream.hpp:161
basic_socket_streambuf< Protocol, Clock, WaitTraits > * rdbuf() const
Return a pointer to the underlying streambuf.
Definition: basic_socket_iostream.hpp:284
Protocol::endpoint connect(basic_socket< Protocol, Executor > &s, const EndpointSequence &endpoints, typename enable_if< is_endpoint_sequence< EndpointSequence >::value >::type *=0)
Establishes a socket connection by trying each endpoint in a sequence.
Definition: connect.hpp:106
Wait traits suitable for use with the basic_waitable_timer class template.
Definition: netfwd.hpp:111
Protocol protocol_type
The protocol type.
Definition: basic_socket_iostream.hpp:158
Class to represent an error code value.
Definition: error_code.hpp:80
time_point expires_at() const
(Deprecated: Use expiry().) Get the stream's expiry time as an absolute time.
Definition: basic_socket_iostream.hpp:320
Iostream streambuf for a socket.
Definition: basic_socket_streambuf.hpp:126
Definition: any_io_executor.hpp:28
basic_socket_iostream()
Construct a basic_socket_iostream without establishing a connection.
Definition: basic_socket_iostream.hpp:188