basic_socket_streambuf.hpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. //
  2. // basic_socket_streambuf.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef ASIO_BASIC_SOCKET_STREAMBUF_HPP
  11. #define ASIO_BASIC_SOCKET_STREAMBUF_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #if !defined(ASIO_NO_IOSTREAM)
  17. #include <streambuf>
  18. #include <vector>
  19. #include "asio/basic_socket.hpp"
  20. #include "asio/basic_stream_socket.hpp"
  21. #include "asio/detail/buffer_sequence_adapter.hpp"
  22. #include "asio/detail/memory.hpp"
  23. #include "asio/detail/throw_error.hpp"
  24. #include "asio/io_context.hpp"
  25. #if defined(ASIO_HAS_BOOST_DATE_TIME) \
  26. && defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
  27. # include "asio/detail/deadline_timer_service.hpp"
  28. #else // defined(ASIO_HAS_BOOST_DATE_TIME)
  29. // && defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
  30. # include "asio/steady_timer.hpp"
  31. #endif // defined(ASIO_HAS_BOOST_DATE_TIME)
  32. // && defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
  33. #include "asio/detail/push_options.hpp"
  34. namespace asio {
  35. namespace detail {
  36. // A separate base class is used to ensure that the io_context member is
  37. // initialised prior to the basic_socket_streambuf's basic_socket base class.
  38. class socket_streambuf_io_context
  39. {
  40. protected:
  41. socket_streambuf_io_context(io_context* ctx)
  42. : default_io_context_(ctx)
  43. {
  44. }
  45. shared_ptr<io_context> default_io_context_;
  46. };
  47. // A separate base class is used to ensure that the dynamically allocated
  48. // buffers are constructed prior to the basic_socket_streambuf's basic_socket
  49. // base class. This makes moving the socket is the last potentially throwing
  50. // step in the streambuf's move constructor, giving the constructor a strong
  51. // exception safety guarantee.
  52. class socket_streambuf_buffers
  53. {
  54. protected:
  55. socket_streambuf_buffers()
  56. : get_buffer_(buffer_size),
  57. put_buffer_(buffer_size)
  58. {
  59. }
  60. enum { buffer_size = 512 };
  61. std::vector<char> get_buffer_;
  62. std::vector<char> put_buffer_;
  63. };
  64. } // namespace detail
  65. #if !defined(ASIO_BASIC_SOCKET_STREAMBUF_FWD_DECL)
  66. #define ASIO_BASIC_SOCKET_STREAMBUF_FWD_DECL
  67. // Forward declaration with defaulted arguments.
  68. template <typename Protocol,
  69. #if defined(ASIO_HAS_BOOST_DATE_TIME) \
  70. && defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
  71. typename Clock = boost::posix_time::ptime,
  72. typename WaitTraits = time_traits<Clock>>
  73. #else // defined(ASIO_HAS_BOOST_DATE_TIME)
  74. // && defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
  75. typename Clock = chrono::steady_clock,
  76. typename WaitTraits = wait_traits<Clock>>
  77. #endif // defined(ASIO_HAS_BOOST_DATE_TIME)
  78. // && defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
  79. class basic_socket_streambuf;
  80. #endif // !defined(ASIO_BASIC_SOCKET_STREAMBUF_FWD_DECL)
  81. /// Iostream streambuf for a socket.
  82. #if defined(GENERATING_DOCUMENTATION)
  83. template <typename Protocol,
  84. typename Clock = chrono::steady_clock,
  85. typename WaitTraits = wait_traits<Clock>>
  86. #else // defined(GENERATING_DOCUMENTATION)
  87. template <typename Protocol, typename Clock, typename WaitTraits>
  88. #endif // defined(GENERATING_DOCUMENTATION)
  89. class basic_socket_streambuf
  90. : public std::streambuf,
  91. private detail::socket_streambuf_io_context,
  92. private detail::socket_streambuf_buffers,
  93. #if defined(ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION)
  94. private basic_socket<Protocol>
  95. #else // defined(ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION)
  96. public basic_socket<Protocol>
  97. #endif // defined(ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION)
  98. {
  99. private:
  100. // These typedefs are intended keep this class's implementation independent
  101. // of whether it's using Boost.DateClock, Boost.Chrono or std::chrono.
  102. #if defined(ASIO_HAS_BOOST_DATE_TIME) \
  103. && defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
  104. typedef WaitTraits traits_helper;
  105. #else // defined(ASIO_HAS_BOOST_DATE_TIME)
  106. // && defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
  107. typedef detail::chrono_time_traits<Clock, WaitTraits> traits_helper;
  108. #endif // defined(ASIO_HAS_BOOST_DATE_TIME)
  109. // && defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
  110. public:
  111. /// The protocol type.
  112. typedef Protocol protocol_type;
  113. /// The endpoint type.
  114. typedef typename Protocol::endpoint endpoint_type;
  115. /// The clock type.
  116. typedef Clock clock_type;
  117. #if defined(GENERATING_DOCUMENTATION)
  118. /// (Deprecated: Use time_point.) The time type.
  119. typedef typename WaitTraits::time_type time_type;
  120. /// The time type.
  121. typedef typename WaitTraits::time_point time_point;
  122. /// (Deprecated: Use duration.) The duration type.
  123. typedef typename WaitTraits::duration_type duration_type;
  124. /// The duration type.
  125. typedef typename WaitTraits::duration duration;
  126. #else
  127. # if !defined(ASIO_NO_DEPRECATED)
  128. typedef typename traits_helper::time_type time_type;
  129. typedef typename traits_helper::duration_type duration_type;
  130. # endif // !defined(ASIO_NO_DEPRECATED)
  131. typedef typename traits_helper::time_type time_point;
  132. typedef typename traits_helper::duration_type duration;
  133. #endif
  134. /// Construct a basic_socket_streambuf without establishing a connection.
  135. basic_socket_streambuf()
  136. : detail::socket_streambuf_io_context(new io_context),
  137. basic_socket<Protocol>(*default_io_context_),
  138. expiry_time_(max_expiry_time())
  139. {
  140. init_buffers();
  141. }
  142. /// Construct a basic_socket_streambuf from the supplied socket.
  143. explicit basic_socket_streambuf(basic_stream_socket<protocol_type> s)
  144. : detail::socket_streambuf_io_context(0),
  145. basic_socket<Protocol>(std::move(s)),
  146. expiry_time_(max_expiry_time())
  147. {
  148. init_buffers();
  149. }
  150. /// Move-construct a basic_socket_streambuf from another.
  151. basic_socket_streambuf(basic_socket_streambuf&& other)
  152. : detail::socket_streambuf_io_context(other),
  153. basic_socket<Protocol>(std::move(other.socket())),
  154. ec_(other.ec_),
  155. expiry_time_(other.expiry_time_)
  156. {
  157. get_buffer_.swap(other.get_buffer_);
  158. put_buffer_.swap(other.put_buffer_);
  159. setg(other.eback(), other.gptr(), other.egptr());
  160. setp(other.pptr(), other.epptr());
  161. other.ec_ = asio::error_code();
  162. other.expiry_time_ = max_expiry_time();
  163. other.init_buffers();
  164. }
  165. /// Move-assign a basic_socket_streambuf from another.
  166. basic_socket_streambuf& operator=(basic_socket_streambuf&& other)
  167. {
  168. this->close();
  169. socket() = std::move(other.socket());
  170. detail::socket_streambuf_io_context::operator=(other);
  171. ec_ = other.ec_;
  172. expiry_time_ = other.expiry_time_;
  173. get_buffer_.swap(other.get_buffer_);
  174. put_buffer_.swap(other.put_buffer_);
  175. setg(other.eback(), other.gptr(), other.egptr());
  176. setp(other.pptr(), other.epptr());
  177. other.ec_ = asio::error_code();
  178. other.expiry_time_ = max_expiry_time();
  179. other.put_buffer_.resize(buffer_size);
  180. other.init_buffers();
  181. return *this;
  182. }
  183. /// Destructor flushes buffered data.
  184. virtual ~basic_socket_streambuf()
  185. {
  186. if (pptr() != pbase())
  187. overflow(traits_type::eof());
  188. }
  189. /// Establish a connection.
  190. /**
  191. * This function establishes a connection to the specified endpoint.
  192. *
  193. * @return \c this if a connection was successfully established, a null
  194. * pointer otherwise.
  195. */
  196. basic_socket_streambuf* connect(const endpoint_type& endpoint)
  197. {
  198. init_buffers();
  199. ec_ = asio::error_code();
  200. this->connect_to_endpoints(&endpoint, &endpoint + 1);
  201. return !ec_ ? this : 0;
  202. }
  203. /// Establish a connection.
  204. /**
  205. * This function automatically establishes a connection based on the supplied
  206. * resolver query parameters. The arguments are used to construct a resolver
  207. * query object.
  208. *
  209. * @return \c this if a connection was successfully established, a null
  210. * pointer otherwise.
  211. */
  212. template <typename... T>
  213. basic_socket_streambuf* connect(T... x)
  214. {
  215. init_buffers();
  216. typedef typename Protocol::resolver resolver_type;
  217. resolver_type resolver(socket().get_executor());
  218. connect_to_endpoints(resolver.resolve(x..., ec_));
  219. return !ec_ ? this : 0;
  220. }
  221. /// Close the connection.
  222. /**
  223. * @return \c this if a connection was successfully established, a null
  224. * pointer otherwise.
  225. */
  226. basic_socket_streambuf* close()
  227. {
  228. sync();
  229. socket().close(ec_);
  230. if (!ec_)
  231. init_buffers();
  232. return !ec_ ? this : 0;
  233. }
  234. /// Get a reference to the underlying socket.
  235. basic_socket<Protocol>& socket()
  236. {
  237. return *this;
  238. }
  239. /// Get the last error associated with the stream buffer.
  240. /**
  241. * @return An \c error_code corresponding to the last error from the stream
  242. * buffer.
  243. */
  244. const asio::error_code& error() const
  245. {
  246. return ec_;
  247. }
  248. #if !defined(ASIO_NO_DEPRECATED)
  249. /// (Deprecated: Use error().) Get the last error associated with the stream
  250. /// buffer.
  251. /**
  252. * @return An \c error_code corresponding to the last error from the stream
  253. * buffer.
  254. */
  255. const asio::error_code& puberror() const
  256. {
  257. return error();
  258. }
  259. /// (Deprecated: Use expiry().) Get the stream buffer's expiry time as an
  260. /// absolute time.
  261. /**
  262. * @return An absolute time value representing the stream buffer's expiry
  263. * time.
  264. */
  265. time_point expires_at() const
  266. {
  267. return expiry_time_;
  268. }
  269. #endif // !defined(ASIO_NO_DEPRECATED)
  270. /// Get the stream buffer's expiry time as an absolute time.
  271. /**
  272. * @return An absolute time value representing the stream buffer's expiry
  273. * time.
  274. */
  275. time_point expiry() const
  276. {
  277. return expiry_time_;
  278. }
  279. /// Set the stream buffer's expiry time as an absolute time.
  280. /**
  281. * This function sets the expiry time associated with the stream. Stream
  282. * operations performed after this time (where the operations cannot be
  283. * completed using the internal buffers) will fail with the error
  284. * asio::error::operation_aborted.
  285. *
  286. * @param expiry_time The expiry time to be used for the stream.
  287. */
  288. void expires_at(const time_point& expiry_time)
  289. {
  290. expiry_time_ = expiry_time;
  291. }
  292. /// Set the stream buffer's expiry time relative to now.
  293. /**
  294. * This function sets the expiry time associated with the stream. Stream
  295. * operations performed after this time (where the operations cannot be
  296. * completed using the internal buffers) will fail with the error
  297. * asio::error::operation_aborted.
  298. *
  299. * @param expiry_time The expiry time to be used for the timer.
  300. */
  301. void expires_after(const duration& expiry_time)
  302. {
  303. expiry_time_ = traits_helper::add(traits_helper::now(), expiry_time);
  304. }
  305. #if !defined(ASIO_NO_DEPRECATED)
  306. /// (Deprecated: Use expiry().) Get the stream buffer's expiry time relative
  307. /// to now.
  308. /**
  309. * @return A relative time value representing the stream buffer's expiry time.
  310. */
  311. duration expires_from_now() const
  312. {
  313. return traits_helper::subtract(expires_at(), traits_helper::now());
  314. }
  315. /// (Deprecated: Use expires_after().) Set the stream buffer's expiry time
  316. /// relative to now.
  317. /**
  318. * This function sets the expiry time associated with the stream. Stream
  319. * operations performed after this time (where the operations cannot be
  320. * completed using the internal buffers) will fail with the error
  321. * asio::error::operation_aborted.
  322. *
  323. * @param expiry_time The expiry time to be used for the timer.
  324. */
  325. void expires_from_now(const duration& expiry_time)
  326. {
  327. expiry_time_ = traits_helper::add(traits_helper::now(), expiry_time);
  328. }
  329. #endif // !defined(ASIO_NO_DEPRECATED)
  330. protected:
  331. int_type underflow()
  332. {
  333. #if defined(ASIO_WINDOWS_RUNTIME)
  334. ec_ = asio::error::operation_not_supported;
  335. return traits_type::eof();
  336. #else // defined(ASIO_WINDOWS_RUNTIME)
  337. if (gptr() != egptr())
  338. return traits_type::eof();
  339. for (;;)
  340. {
  341. // Check if we are past the expiry time.
  342. if (traits_helper::less_than(expiry_time_, traits_helper::now()))
  343. {
  344. ec_ = asio::error::timed_out;
  345. return traits_type::eof();
  346. }
  347. // Try to complete the operation without blocking.
  348. if (!socket().native_non_blocking())
  349. socket().native_non_blocking(true, ec_);
  350. detail::buffer_sequence_adapter<mutable_buffer, mutable_buffer>
  351. bufs(asio::buffer(get_buffer_) + putback_max);
  352. detail::signed_size_type bytes = detail::socket_ops::recv(
  353. socket().native_handle(), bufs.buffers(), bufs.count(), 0, ec_);
  354. // Check if operation succeeded.
  355. if (bytes > 0)
  356. {
  357. setg(&get_buffer_[0], &get_buffer_[0] + putback_max,
  358. &get_buffer_[0] + putback_max + bytes);
  359. return traits_type::to_int_type(*gptr());
  360. }
  361. // Check for EOF.
  362. if (bytes == 0)
  363. {
  364. ec_ = asio::error::eof;
  365. return traits_type::eof();
  366. }
  367. // Operation failed.
  368. if (ec_ != asio::error::would_block
  369. && ec_ != asio::error::try_again)
  370. return traits_type::eof();
  371. // Wait for socket to become ready.
  372. if (detail::socket_ops::poll_read(
  373. socket().native_handle(), 0, timeout(), ec_) < 0)
  374. return traits_type::eof();
  375. }
  376. #endif // defined(ASIO_WINDOWS_RUNTIME)
  377. }
  378. int_type overflow(int_type c)
  379. {
  380. #if defined(ASIO_WINDOWS_RUNTIME)
  381. ec_ = asio::error::operation_not_supported;
  382. return traits_type::eof();
  383. #else // defined(ASIO_WINDOWS_RUNTIME)
  384. char_type ch = traits_type::to_char_type(c);
  385. // Determine what needs to be sent.
  386. const_buffer output_buffer;
  387. if (put_buffer_.empty())
  388. {
  389. if (traits_type::eq_int_type(c, traits_type::eof()))
  390. return traits_type::not_eof(c); // Nothing to do.
  391. output_buffer = asio::buffer(&ch, sizeof(char_type));
  392. }
  393. else
  394. {
  395. output_buffer = asio::buffer(pbase(),
  396. (pptr() - pbase()) * sizeof(char_type));
  397. }
  398. while (output_buffer.size() > 0)
  399. {
  400. // Check if we are past the expiry time.
  401. if (traits_helper::less_than(expiry_time_, traits_helper::now()))
  402. {
  403. ec_ = asio::error::timed_out;
  404. return traits_type::eof();
  405. }
  406. // Try to complete the operation without blocking.
  407. if (!socket().native_non_blocking())
  408. socket().native_non_blocking(true, ec_);
  409. detail::buffer_sequence_adapter<
  410. const_buffer, const_buffer> bufs(output_buffer);
  411. detail::signed_size_type bytes = detail::socket_ops::send(
  412. socket().native_handle(), bufs.buffers(), bufs.count(), 0, ec_);
  413. // Check if operation succeeded.
  414. if (bytes > 0)
  415. {
  416. output_buffer += static_cast<std::size_t>(bytes);
  417. continue;
  418. }
  419. // Operation failed.
  420. if (ec_ != asio::error::would_block
  421. && ec_ != asio::error::try_again)
  422. return traits_type::eof();
  423. // Wait for socket to become ready.
  424. if (detail::socket_ops::poll_write(
  425. socket().native_handle(), 0, timeout(), ec_) < 0)
  426. return traits_type::eof();
  427. }
  428. if (!put_buffer_.empty())
  429. {
  430. setp(&put_buffer_[0], &put_buffer_[0] + put_buffer_.size());
  431. // If the new character is eof then our work here is done.
  432. if (traits_type::eq_int_type(c, traits_type::eof()))
  433. return traits_type::not_eof(c);
  434. // Add the new character to the output buffer.
  435. *pptr() = ch;
  436. pbump(1);
  437. }
  438. return c;
  439. #endif // defined(ASIO_WINDOWS_RUNTIME)
  440. }
  441. int sync()
  442. {
  443. return overflow(traits_type::eof());
  444. }
  445. std::streambuf* setbuf(char_type* s, std::streamsize n)
  446. {
  447. if (pptr() == pbase() && s == 0 && n == 0)
  448. {
  449. put_buffer_.clear();
  450. setp(0, 0);
  451. sync();
  452. return this;
  453. }
  454. return 0;
  455. }
  456. private:
  457. // Disallow copying and assignment.
  458. basic_socket_streambuf(const basic_socket_streambuf&) = delete;
  459. basic_socket_streambuf& operator=(
  460. const basic_socket_streambuf&) = delete;
  461. void init_buffers()
  462. {
  463. setg(&get_buffer_[0],
  464. &get_buffer_[0] + putback_max,
  465. &get_buffer_[0] + putback_max);
  466. if (put_buffer_.empty())
  467. setp(0, 0);
  468. else
  469. setp(&put_buffer_[0], &put_buffer_[0] + put_buffer_.size());
  470. }
  471. int timeout() const
  472. {
  473. int64_t msec = traits_helper::to_posix_duration(
  474. traits_helper::subtract(expiry_time_,
  475. traits_helper::now())).total_milliseconds();
  476. if (msec > (std::numeric_limits<int>::max)())
  477. msec = (std::numeric_limits<int>::max)();
  478. else if (msec < 0)
  479. msec = 0;
  480. return static_cast<int>(msec);
  481. }
  482. template <typename EndpointSequence>
  483. void connect_to_endpoints(const EndpointSequence& endpoints)
  484. {
  485. this->connect_to_endpoints(endpoints.begin(), endpoints.end());
  486. }
  487. template <typename EndpointIterator>
  488. void connect_to_endpoints(EndpointIterator begin, EndpointIterator end)
  489. {
  490. #if defined(ASIO_WINDOWS_RUNTIME)
  491. ec_ = asio::error::operation_not_supported;
  492. #else // defined(ASIO_WINDOWS_RUNTIME)
  493. if (ec_)
  494. return;
  495. ec_ = asio::error::not_found;
  496. for (EndpointIterator i = begin; i != end; ++i)
  497. {
  498. // Check if we are past the expiry time.
  499. if (traits_helper::less_than(expiry_time_, traits_helper::now()))
  500. {
  501. ec_ = asio::error::timed_out;
  502. return;
  503. }
  504. // Close and reopen the socket.
  505. typename Protocol::endpoint ep(*i);
  506. socket().close(ec_);
  507. socket().open(ep.protocol(), ec_);
  508. if (ec_)
  509. continue;
  510. // Try to complete the operation without blocking.
  511. if (!socket().native_non_blocking())
  512. socket().native_non_blocking(true, ec_);
  513. detail::socket_ops::connect(socket().native_handle(),
  514. ep.data(), ep.size(), ec_);
  515. // Check if operation succeeded.
  516. if (!ec_)
  517. return;
  518. // Operation failed.
  519. if (ec_ != asio::error::in_progress
  520. && ec_ != asio::error::would_block)
  521. continue;
  522. // Wait for socket to become ready.
  523. if (detail::socket_ops::poll_connect(
  524. socket().native_handle(), timeout(), ec_) < 0)
  525. continue;
  526. // Get the error code from the connect operation.
  527. int connect_error = 0;
  528. size_t connect_error_len = sizeof(connect_error);
  529. if (detail::socket_ops::getsockopt(socket().native_handle(), 0,
  530. SOL_SOCKET, SO_ERROR, &connect_error, &connect_error_len, ec_)
  531. == detail::socket_error_retval)
  532. return;
  533. // Check the result of the connect operation.
  534. ec_ = asio::error_code(connect_error,
  535. asio::error::get_system_category());
  536. if (!ec_)
  537. return;
  538. }
  539. #endif // defined(ASIO_WINDOWS_RUNTIME)
  540. }
  541. // Helper function to get the maximum expiry time.
  542. static time_point max_expiry_time()
  543. {
  544. #if defined(ASIO_HAS_BOOST_DATE_TIME) \
  545. && defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
  546. return boost::posix_time::pos_infin;
  547. #else // defined(ASIO_HAS_BOOST_DATE_TIME)
  548. // && defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
  549. return (time_point::max)();
  550. #endif // defined(ASIO_HAS_BOOST_DATE_TIME)
  551. // && defined(ASIO_USE_BOOST_DATE_TIME_FOR_SOCKET_IOSTREAM)
  552. }
  553. enum { putback_max = 8 };
  554. asio::error_code ec_;
  555. time_point expiry_time_;
  556. };
  557. } // namespace asio
  558. #include "asio/detail/pop_options.hpp"
  559. #endif // !defined(ASIO_NO_IOSTREAM)
  560. #endif // ASIO_BASIC_SOCKET_STREAMBUF_HPP