basic_deadline_timer.hpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. //
  2. // basic_deadline_timer.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2018 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 BOOST_ASIO_BASIC_DEADLINE_TIMER_HPP
  11. #define BOOST_ASIO_BASIC_DEADLINE_TIMER_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) \
  17. || defined(GENERATING_DOCUMENTATION)
  18. #include <cstddef>
  19. #include <boost/asio/basic_io_object.hpp>
  20. #include <boost/asio/detail/handler_type_requirements.hpp>
  21. #include <boost/asio/detail/throw_error.hpp>
  22. #include <boost/asio/error.hpp>
  23. #include <boost/asio/time_traits.hpp>
  24. #if defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
  25. # include <boost/asio/deadline_timer_service.hpp>
  26. #else // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
  27. # include <boost/asio/detail/deadline_timer_service.hpp>
  28. # define BOOST_ASIO_SVC_T detail::deadline_timer_service<TimeTraits>
  29. #endif // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
  30. #include <boost/asio/detail/push_options.hpp>
  31. namespace boost {
  32. namespace asio {
  33. /// Provides waitable timer functionality.
  34. /**
  35. * The basic_deadline_timer class template provides the ability to perform a
  36. * blocking or asynchronous wait for a timer to expire.
  37. *
  38. * A deadline timer is always in one of two states: "expired" or "not expired".
  39. * If the wait() or async_wait() function is called on an expired timer, the
  40. * wait operation will complete immediately.
  41. *
  42. * Most applications will use the boost::asio::deadline_timer typedef.
  43. *
  44. * @par Thread Safety
  45. * @e Distinct @e objects: Safe.@n
  46. * @e Shared @e objects: Unsafe.
  47. *
  48. * @par Examples
  49. * Performing a blocking wait:
  50. * @code
  51. * // Construct a timer without setting an expiry time.
  52. * boost::asio::deadline_timer timer(io_context);
  53. *
  54. * // Set an expiry time relative to now.
  55. * timer.expires_from_now(boost::posix_time::seconds(5));
  56. *
  57. * // Wait for the timer to expire.
  58. * timer.wait();
  59. * @endcode
  60. *
  61. * @par
  62. * Performing an asynchronous wait:
  63. * @code
  64. * void handler(const boost::system::error_code& error)
  65. * {
  66. * if (!error)
  67. * {
  68. * // Timer expired.
  69. * }
  70. * }
  71. *
  72. * ...
  73. *
  74. * // Construct a timer with an absolute expiry time.
  75. * boost::asio::deadline_timer timer(io_context,
  76. * boost::posix_time::time_from_string("2005-12-07 23:59:59.000"));
  77. *
  78. * // Start an asynchronous wait.
  79. * timer.async_wait(handler);
  80. * @endcode
  81. *
  82. * @par Changing an active deadline_timer's expiry time
  83. *
  84. * Changing the expiry time of a timer while there are pending asynchronous
  85. * waits causes those wait operations to be cancelled. To ensure that the action
  86. * associated with the timer is performed only once, use something like this:
  87. * used:
  88. *
  89. * @code
  90. * void on_some_event()
  91. * {
  92. * if (my_timer.expires_from_now(seconds(5)) > 0)
  93. * {
  94. * // We managed to cancel the timer. Start new asynchronous wait.
  95. * my_timer.async_wait(on_timeout);
  96. * }
  97. * else
  98. * {
  99. * // Too late, timer has already expired!
  100. * }
  101. * }
  102. *
  103. * void on_timeout(const boost::system::error_code& e)
  104. * {
  105. * if (e != boost::asio::error::operation_aborted)
  106. * {
  107. * // Timer was not cancelled, take necessary action.
  108. * }
  109. * }
  110. * @endcode
  111. *
  112. * @li The boost::asio::basic_deadline_timer::expires_from_now() function
  113. * cancels any pending asynchronous waits, and returns the number of
  114. * asynchronous waits that were cancelled. If it returns 0 then you were too
  115. * late and the wait handler has already been executed, or will soon be
  116. * executed. If it returns 1 then the wait handler was successfully cancelled.
  117. *
  118. * @li If a wait handler is cancelled, the boost::system::error_code passed to
  119. * it contains the value boost::asio::error::operation_aborted.
  120. */
  121. template <typename Time,
  122. typename TimeTraits = boost::asio::time_traits<Time>
  123. BOOST_ASIO_SVC_TPARAM_DEF2(= deadline_timer_service<Time, TimeTraits>)>
  124. class basic_deadline_timer
  125. : BOOST_ASIO_SVC_ACCESS basic_io_object<BOOST_ASIO_SVC_T>
  126. {
  127. public:
  128. /// The type of the executor associated with the object.
  129. typedef io_context::executor_type executor_type;
  130. /// The time traits type.
  131. typedef TimeTraits traits_type;
  132. /// The time type.
  133. typedef typename traits_type::time_type time_type;
  134. /// The duration type.
  135. typedef typename traits_type::duration_type duration_type;
  136. /// Constructor.
  137. /**
  138. * This constructor creates a timer without setting an expiry time. The
  139. * expires_at() or expires_from_now() functions must be called to set an
  140. * expiry time before the timer can be waited on.
  141. *
  142. * @param io_context The io_context object that the timer will use to dispatch
  143. * handlers for any asynchronous operations performed on the timer.
  144. */
  145. explicit basic_deadline_timer(boost::asio::io_context& io_context)
  146. : basic_io_object<BOOST_ASIO_SVC_T>(io_context)
  147. {
  148. }
  149. /// Constructor to set a particular expiry time as an absolute time.
  150. /**
  151. * This constructor creates a timer and sets the expiry time.
  152. *
  153. * @param io_context The io_context object that the timer will use to dispatch
  154. * handlers for any asynchronous operations performed on the timer.
  155. *
  156. * @param expiry_time The expiry time to be used for the timer, expressed
  157. * as an absolute time.
  158. */
  159. basic_deadline_timer(boost::asio::io_context& io_context,
  160. const time_type& expiry_time)
  161. : basic_io_object<BOOST_ASIO_SVC_T>(io_context)
  162. {
  163. boost::system::error_code ec;
  164. this->get_service().expires_at(this->get_implementation(), expiry_time, ec);
  165. boost::asio::detail::throw_error(ec, "expires_at");
  166. }
  167. /// Constructor to set a particular expiry time relative to now.
  168. /**
  169. * This constructor creates a timer and sets the expiry time.
  170. *
  171. * @param io_context The io_context object that the timer will use to dispatch
  172. * handlers for any asynchronous operations performed on the timer.
  173. *
  174. * @param expiry_time The expiry time to be used for the timer, relative to
  175. * now.
  176. */
  177. basic_deadline_timer(boost::asio::io_context& io_context,
  178. const duration_type& expiry_time)
  179. : basic_io_object<BOOST_ASIO_SVC_T>(io_context)
  180. {
  181. boost::system::error_code ec;
  182. this->get_service().expires_from_now(
  183. this->get_implementation(), expiry_time, ec);
  184. boost::asio::detail::throw_error(ec, "expires_from_now");
  185. }
  186. #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
  187. /// Move-construct a basic_deadline_timer from another.
  188. /**
  189. * This constructor moves a timer from one object to another.
  190. *
  191. * @param other The other basic_deadline_timer object from which the move will
  192. * occur.
  193. *
  194. * @note Following the move, the moved-from object is in the same state as if
  195. * constructed using the @c basic_deadline_timer(io_context&) constructor.
  196. */
  197. basic_deadline_timer(basic_deadline_timer&& other)
  198. : basic_io_object<BOOST_ASIO_SVC_T>(std::move(other))
  199. {
  200. }
  201. /// Move-assign a basic_deadline_timer from another.
  202. /**
  203. * This assignment operator moves a timer from one object to another. Cancels
  204. * any outstanding asynchronous operations associated with the target object.
  205. *
  206. * @param other The other basic_deadline_timer object from which the move will
  207. * occur.
  208. *
  209. * @note Following the move, the moved-from object is in the same state as if
  210. * constructed using the @c basic_deadline_timer(io_context&) constructor.
  211. */
  212. basic_deadline_timer& operator=(basic_deadline_timer&& other)
  213. {
  214. basic_io_object<BOOST_ASIO_SVC_T>::operator=(std::move(other));
  215. return *this;
  216. }
  217. #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
  218. /// Destroys the timer.
  219. /**
  220. * This function destroys the timer, cancelling any outstanding asynchronous
  221. * wait operations associated with the timer as if by calling @c cancel.
  222. */
  223. ~basic_deadline_timer()
  224. {
  225. }
  226. #if defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
  227. // These functions are provided by basic_io_object<>.
  228. #else // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
  229. #if !defined(BOOST_ASIO_NO_DEPRECATED)
  230. /// (Deprecated: Use get_executor().) Get the io_context associated with the
  231. /// object.
  232. /**
  233. * This function may be used to obtain the io_context object that the I/O
  234. * object uses to dispatch handlers for asynchronous operations.
  235. *
  236. * @return A reference to the io_context object that the I/O object will use
  237. * to dispatch handlers. Ownership is not transferred to the caller.
  238. */
  239. boost::asio::io_context& get_io_context()
  240. {
  241. return basic_io_object<BOOST_ASIO_SVC_T>::get_io_context();
  242. }
  243. /// (Deprecated: Use get_executor().) Get the io_context associated with the
  244. /// object.
  245. /**
  246. * This function may be used to obtain the io_context object that the I/O
  247. * object uses to dispatch handlers for asynchronous operations.
  248. *
  249. * @return A reference to the io_context object that the I/O object will use
  250. * to dispatch handlers. Ownership is not transferred to the caller.
  251. */
  252. boost::asio::io_context& get_io_service()
  253. {
  254. return basic_io_object<BOOST_ASIO_SVC_T>::get_io_service();
  255. }
  256. #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
  257. /// Get the executor associated with the object.
  258. executor_type get_executor() BOOST_ASIO_NOEXCEPT
  259. {
  260. return basic_io_object<BOOST_ASIO_SVC_T>::get_executor();
  261. }
  262. #endif // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
  263. /// Cancel any asynchronous operations that are waiting on the timer.
  264. /**
  265. * This function forces the completion of any pending asynchronous wait
  266. * operations against the timer. The handler for each cancelled operation will
  267. * be invoked with the boost::asio::error::operation_aborted error code.
  268. *
  269. * Cancelling the timer does not change the expiry time.
  270. *
  271. * @return The number of asynchronous operations that were cancelled.
  272. *
  273. * @throws boost::system::system_error Thrown on failure.
  274. *
  275. * @note If the timer has already expired when cancel() is called, then the
  276. * handlers for asynchronous wait operations will:
  277. *
  278. * @li have already been invoked; or
  279. *
  280. * @li have been queued for invocation in the near future.
  281. *
  282. * These handlers can no longer be cancelled, and therefore are passed an
  283. * error code that indicates the successful completion of the wait operation.
  284. */
  285. std::size_t cancel()
  286. {
  287. boost::system::error_code ec;
  288. std::size_t s = this->get_service().cancel(this->get_implementation(), ec);
  289. boost::asio::detail::throw_error(ec, "cancel");
  290. return s;
  291. }
  292. /// Cancel any asynchronous operations that are waiting on the timer.
  293. /**
  294. * This function forces the completion of any pending asynchronous wait
  295. * operations against the timer. The handler for each cancelled operation will
  296. * be invoked with the boost::asio::error::operation_aborted error code.
  297. *
  298. * Cancelling the timer does not change the expiry time.
  299. *
  300. * @param ec Set to indicate what error occurred, if any.
  301. *
  302. * @return The number of asynchronous operations that were cancelled.
  303. *
  304. * @note If the timer has already expired when cancel() is called, then the
  305. * handlers for asynchronous wait operations will:
  306. *
  307. * @li have already been invoked; or
  308. *
  309. * @li have been queued for invocation in the near future.
  310. *
  311. * These handlers can no longer be cancelled, and therefore are passed an
  312. * error code that indicates the successful completion of the wait operation.
  313. */
  314. std::size_t cancel(boost::system::error_code& ec)
  315. {
  316. return this->get_service().cancel(this->get_implementation(), ec);
  317. }
  318. /// Cancels one asynchronous operation that is waiting on the timer.
  319. /**
  320. * This function forces the completion of one pending asynchronous wait
  321. * operation against the timer. Handlers are cancelled in FIFO order. The
  322. * handler for the cancelled operation will be invoked with the
  323. * boost::asio::error::operation_aborted error code.
  324. *
  325. * Cancelling the timer does not change the expiry time.
  326. *
  327. * @return The number of asynchronous operations that were cancelled. That is,
  328. * either 0 or 1.
  329. *
  330. * @throws boost::system::system_error Thrown on failure.
  331. *
  332. * @note If the timer has already expired when cancel_one() is called, then
  333. * the handlers for asynchronous wait operations will:
  334. *
  335. * @li have already been invoked; or
  336. *
  337. * @li have been queued for invocation in the near future.
  338. *
  339. * These handlers can no longer be cancelled, and therefore are passed an
  340. * error code that indicates the successful completion of the wait operation.
  341. */
  342. std::size_t cancel_one()
  343. {
  344. boost::system::error_code ec;
  345. std::size_t s = this->get_service().cancel_one(
  346. this->get_implementation(), ec);
  347. boost::asio::detail::throw_error(ec, "cancel_one");
  348. return s;
  349. }
  350. /// Cancels one asynchronous operation that is waiting on the timer.
  351. /**
  352. * This function forces the completion of one pending asynchronous wait
  353. * operation against the timer. Handlers are cancelled in FIFO order. The
  354. * handler for the cancelled operation will be invoked with the
  355. * boost::asio::error::operation_aborted error code.
  356. *
  357. * Cancelling the timer does not change the expiry time.
  358. *
  359. * @param ec Set to indicate what error occurred, if any.
  360. *
  361. * @return The number of asynchronous operations that were cancelled. That is,
  362. * either 0 or 1.
  363. *
  364. * @note If the timer has already expired when cancel_one() is called, then
  365. * the handlers for asynchronous wait operations will:
  366. *
  367. * @li have already been invoked; or
  368. *
  369. * @li have been queued for invocation in the near future.
  370. *
  371. * These handlers can no longer be cancelled, and therefore are passed an
  372. * error code that indicates the successful completion of the wait operation.
  373. */
  374. std::size_t cancel_one(boost::system::error_code& ec)
  375. {
  376. return this->get_service().cancel_one(this->get_implementation(), ec);
  377. }
  378. /// Get the timer's expiry time as an absolute time.
  379. /**
  380. * This function may be used to obtain the timer's current expiry time.
  381. * Whether the timer has expired or not does not affect this value.
  382. */
  383. time_type expires_at() const
  384. {
  385. return this->get_service().expires_at(this->get_implementation());
  386. }
  387. /// Set the timer's expiry time as an absolute time.
  388. /**
  389. * This function sets the expiry time. Any pending asynchronous wait
  390. * operations will be cancelled. The handler for each cancelled operation will
  391. * be invoked with the boost::asio::error::operation_aborted error code.
  392. *
  393. * @param expiry_time The expiry time to be used for the timer.
  394. *
  395. * @return The number of asynchronous operations that were cancelled.
  396. *
  397. * @throws boost::system::system_error Thrown on failure.
  398. *
  399. * @note If the timer has already expired when expires_at() is called, then
  400. * the handlers for asynchronous wait operations will:
  401. *
  402. * @li have already been invoked; or
  403. *
  404. * @li have been queued for invocation in the near future.
  405. *
  406. * These handlers can no longer be cancelled, and therefore are passed an
  407. * error code that indicates the successful completion of the wait operation.
  408. */
  409. std::size_t expires_at(const time_type& expiry_time)
  410. {
  411. boost::system::error_code ec;
  412. std::size_t s = this->get_service().expires_at(
  413. this->get_implementation(), expiry_time, ec);
  414. boost::asio::detail::throw_error(ec, "expires_at");
  415. return s;
  416. }
  417. /// Set the timer's expiry time as an absolute time.
  418. /**
  419. * This function sets the expiry time. Any pending asynchronous wait
  420. * operations will be cancelled. The handler for each cancelled operation will
  421. * be invoked with the boost::asio::error::operation_aborted error code.
  422. *
  423. * @param expiry_time The expiry time to be used for the timer.
  424. *
  425. * @param ec Set to indicate what error occurred, if any.
  426. *
  427. * @return The number of asynchronous operations that were cancelled.
  428. *
  429. * @note If the timer has already expired when expires_at() is called, then
  430. * the handlers for asynchronous wait operations will:
  431. *
  432. * @li have already been invoked; or
  433. *
  434. * @li have been queued for invocation in the near future.
  435. *
  436. * These handlers can no longer be cancelled, and therefore are passed an
  437. * error code that indicates the successful completion of the wait operation.
  438. */
  439. std::size_t expires_at(const time_type& expiry_time,
  440. boost::system::error_code& ec)
  441. {
  442. return this->get_service().expires_at(
  443. this->get_implementation(), expiry_time, ec);
  444. }
  445. /// Get the timer's expiry time relative to now.
  446. /**
  447. * This function may be used to obtain the timer's current expiry time.
  448. * Whether the timer has expired or not does not affect this value.
  449. */
  450. duration_type expires_from_now() const
  451. {
  452. return this->get_service().expires_from_now(this->get_implementation());
  453. }
  454. /// Set the timer's expiry time relative to now.
  455. /**
  456. * This function sets the expiry time. Any pending asynchronous wait
  457. * operations will be cancelled. The handler for each cancelled operation will
  458. * be invoked with the boost::asio::error::operation_aborted error code.
  459. *
  460. * @param expiry_time The expiry time to be used for the timer.
  461. *
  462. * @return The number of asynchronous operations that were cancelled.
  463. *
  464. * @throws boost::system::system_error Thrown on failure.
  465. *
  466. * @note If the timer has already expired when expires_from_now() is called,
  467. * then the handlers for asynchronous wait operations will:
  468. *
  469. * @li have already been invoked; or
  470. *
  471. * @li have been queued for invocation in the near future.
  472. *
  473. * These handlers can no longer be cancelled, and therefore are passed an
  474. * error code that indicates the successful completion of the wait operation.
  475. */
  476. std::size_t expires_from_now(const duration_type& expiry_time)
  477. {
  478. boost::system::error_code ec;
  479. std::size_t s = this->get_service().expires_from_now(
  480. this->get_implementation(), expiry_time, ec);
  481. boost::asio::detail::throw_error(ec, "expires_from_now");
  482. return s;
  483. }
  484. /// Set the timer's expiry time relative to now.
  485. /**
  486. * This function sets the expiry time. Any pending asynchronous wait
  487. * operations will be cancelled. The handler for each cancelled operation will
  488. * be invoked with the boost::asio::error::operation_aborted error code.
  489. *
  490. * @param expiry_time The expiry time to be used for the timer.
  491. *
  492. * @param ec Set to indicate what error occurred, if any.
  493. *
  494. * @return The number of asynchronous operations that were cancelled.
  495. *
  496. * @note If the timer has already expired when expires_from_now() is called,
  497. * then the handlers for asynchronous wait operations will:
  498. *
  499. * @li have already been invoked; or
  500. *
  501. * @li have been queued for invocation in the near future.
  502. *
  503. * These handlers can no longer be cancelled, and therefore are passed an
  504. * error code that indicates the successful completion of the wait operation.
  505. */
  506. std::size_t expires_from_now(const duration_type& expiry_time,
  507. boost::system::error_code& ec)
  508. {
  509. return this->get_service().expires_from_now(
  510. this->get_implementation(), expiry_time, ec);
  511. }
  512. /// Perform a blocking wait on the timer.
  513. /**
  514. * This function is used to wait for the timer to expire. This function
  515. * blocks and does not return until the timer has expired.
  516. *
  517. * @throws boost::system::system_error Thrown on failure.
  518. */
  519. void wait()
  520. {
  521. boost::system::error_code ec;
  522. this->get_service().wait(this->get_implementation(), ec);
  523. boost::asio::detail::throw_error(ec, "wait");
  524. }
  525. /// Perform a blocking wait on the timer.
  526. /**
  527. * This function is used to wait for the timer to expire. This function
  528. * blocks and does not return until the timer has expired.
  529. *
  530. * @param ec Set to indicate what error occurred, if any.
  531. */
  532. void wait(boost::system::error_code& ec)
  533. {
  534. this->get_service().wait(this->get_implementation(), ec);
  535. }
  536. /// Start an asynchronous wait on the timer.
  537. /**
  538. * This function may be used to initiate an asynchronous wait against the
  539. * timer. It always returns immediately.
  540. *
  541. * For each call to async_wait(), the supplied handler will be called exactly
  542. * once. The handler will be called when:
  543. *
  544. * @li The timer has expired.
  545. *
  546. * @li The timer was cancelled, in which case the handler is passed the error
  547. * code boost::asio::error::operation_aborted.
  548. *
  549. * @param handler The handler to be called when the timer expires. Copies
  550. * will be made of the handler as required. The function signature of the
  551. * handler must be:
  552. * @code void handler(
  553. * const boost::system::error_code& error // Result of operation.
  554. * ); @endcode
  555. * Regardless of whether the asynchronous operation completes immediately or
  556. * not, the handler will not be invoked from within this function. Invocation
  557. * of the handler will be performed in a manner equivalent to using
  558. * boost::asio::io_context::post().
  559. */
  560. template <typename WaitHandler>
  561. BOOST_ASIO_INITFN_RESULT_TYPE(WaitHandler,
  562. void (boost::system::error_code))
  563. async_wait(BOOST_ASIO_MOVE_ARG(WaitHandler) handler)
  564. {
  565. // If you get an error on the following line it means that your handler does
  566. // not meet the documented type requirements for a WaitHandler.
  567. BOOST_ASIO_WAIT_HANDLER_CHECK(WaitHandler, handler) type_check;
  568. #if defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
  569. return this->get_service().async_wait(this->get_implementation(),
  570. BOOST_ASIO_MOVE_CAST(WaitHandler)(handler));
  571. #else // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
  572. async_completion<WaitHandler,
  573. void (boost::system::error_code)> init(handler);
  574. this->get_service().async_wait(this->get_implementation(),
  575. init.completion_handler);
  576. return init.result.get();
  577. #endif // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
  578. }
  579. };
  580. } // namespace asio
  581. } // namespace boost
  582. #include <boost/asio/detail/pop_options.hpp>
  583. #if !defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
  584. # undef BOOST_ASIO_SVC_T
  585. #endif // !defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
  586. #endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
  587. // || defined(GENERATING_DOCUMENTATION)
  588. #endif // BOOST_ASIO_BASIC_DEADLINE_TIMER_HPP