![]() |
|
|||
File indexing completed on 2025-09-16 08:29:08
0001 // 0002 // basic_deadline_timer.hpp 0003 // ~~~~~~~~~~~~~~~~~~~~~~~~ 0004 // 0005 // Copyright (c) 2003-2025 Christopher M. Kohlhoff (chris at kohlhoff dot com) 0006 // 0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying 0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 0009 // 0010 0011 #ifndef BOOST_ASIO_BASIC_DEADLINE_TIMER_HPP 0012 #define BOOST_ASIO_BASIC_DEADLINE_TIMER_HPP 0013 0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 0015 # pragma once 0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 0017 0018 #include <boost/asio/detail/config.hpp> 0019 0020 #if !defined(BOOST_ASIO_NO_DEPRECATED) 0021 0022 #if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) \ 0023 || defined(GENERATING_DOCUMENTATION) 0024 0025 #include <cstddef> 0026 #include <boost/asio/any_io_executor.hpp> 0027 #include <boost/asio/detail/deadline_timer_service.hpp> 0028 #include <boost/asio/detail/handler_type_requirements.hpp> 0029 #include <boost/asio/detail/io_object_impl.hpp> 0030 #include <boost/asio/detail/non_const_lvalue.hpp> 0031 #include <boost/asio/detail/throw_error.hpp> 0032 #include <boost/asio/error.hpp> 0033 #include <boost/asio/execution_context.hpp> 0034 #include <boost/asio/time_traits.hpp> 0035 0036 #include <boost/asio/detail/push_options.hpp> 0037 0038 namespace boost { 0039 namespace asio { 0040 0041 /// (Deprecated: Use basic_waitable_timer.) Provides waitable timer 0042 /// functionality. 0043 /** 0044 * The basic_deadline_timer class template provides the ability to perform a 0045 * blocking or asynchronous wait for a timer to expire. 0046 * 0047 * A deadline timer is always in one of two states: "expired" or "not expired". 0048 * If the wait() or async_wait() function is called on an expired timer, the 0049 * wait operation will complete immediately. 0050 * 0051 * Most applications will use the boost::asio::deadline_timer typedef. 0052 * 0053 * @par Thread Safety 0054 * @e Distinct @e objects: Safe.@n 0055 * @e Shared @e objects: Unsafe. 0056 * 0057 * @par Examples 0058 * Performing a blocking wait: 0059 * @code 0060 * // Construct a timer without setting an expiry time. 0061 * boost::asio::deadline_timer timer(my_context); 0062 * 0063 * // Set an expiry time relative to now. 0064 * timer.expires_from_now(boost::posix_time::seconds(5)); 0065 * 0066 * // Wait for the timer to expire. 0067 * timer.wait(); 0068 * @endcode 0069 * 0070 * @par 0071 * Performing an asynchronous wait: 0072 * @code 0073 * void handler(const boost::system::error_code& error) 0074 * { 0075 * if (!error) 0076 * { 0077 * // Timer expired. 0078 * } 0079 * } 0080 * 0081 * ... 0082 * 0083 * // Construct a timer with an absolute expiry time. 0084 * boost::asio::deadline_timer timer(my_context, 0085 * boost::posix_time::time_from_string("2005-12-07 23:59:59.000")); 0086 * 0087 * // Start an asynchronous wait. 0088 * timer.async_wait(handler); 0089 * @endcode 0090 * 0091 * @par Changing an active deadline_timer's expiry time 0092 * 0093 * Changing the expiry time of a timer while there are pending asynchronous 0094 * waits causes those wait operations to be cancelled. To ensure that the action 0095 * associated with the timer is performed only once, use something like this: 0096 * used: 0097 * 0098 * @code 0099 * void on_some_event() 0100 * { 0101 * if (my_timer.expires_from_now(seconds(5)) > 0) 0102 * { 0103 * // We managed to cancel the timer. Start new asynchronous wait. 0104 * my_timer.async_wait(on_timeout); 0105 * } 0106 * else 0107 * { 0108 * // Too late, timer has already expired! 0109 * } 0110 * } 0111 * 0112 * void on_timeout(const boost::system::error_code& e) 0113 * { 0114 * if (e != boost::asio::error::operation_aborted) 0115 * { 0116 * // Timer was not cancelled, take necessary action. 0117 * } 0118 * } 0119 * @endcode 0120 * 0121 * @li The boost::asio::basic_deadline_timer::expires_from_now() function 0122 * cancels any pending asynchronous waits, and returns the number of 0123 * asynchronous waits that were cancelled. If it returns 0 then you were too 0124 * late and the wait handler has already been executed, or will soon be 0125 * executed. If it returns 1 then the wait handler was successfully cancelled. 0126 * 0127 * @li If a wait handler is cancelled, the boost::system::error_code passed to 0128 * it contains the value boost::asio::error::operation_aborted. 0129 */ 0130 template <typename Time, 0131 typename TimeTraits = boost::asio::time_traits<Time>, 0132 typename Executor = any_io_executor> 0133 class basic_deadline_timer 0134 { 0135 private: 0136 class initiate_async_wait; 0137 0138 public: 0139 /// The type of the executor associated with the object. 0140 typedef Executor executor_type; 0141 0142 /// Rebinds the timer type to another executor. 0143 template <typename Executor1> 0144 struct rebind_executor 0145 { 0146 /// The timer type when rebound to the specified executor. 0147 typedef basic_deadline_timer<Time, TimeTraits, Executor1> other; 0148 }; 0149 0150 /// The time traits type. 0151 typedef TimeTraits traits_type; 0152 0153 /// The time type. 0154 typedef typename traits_type::time_type time_type; 0155 0156 /// The duration type. 0157 typedef typename traits_type::duration_type duration_type; 0158 0159 /// Constructor. 0160 /** 0161 * This constructor creates a timer without setting an expiry time. The 0162 * expires_at() or expires_from_now() functions must be called to set an 0163 * expiry time before the timer can be waited on. 0164 * 0165 * @param ex The I/O executor that the timer will use, by default, to 0166 * dispatch handlers for any asynchronous operations performed on the timer. 0167 */ 0168 explicit basic_deadline_timer(const executor_type& ex) 0169 : impl_(0, ex) 0170 { 0171 } 0172 0173 /// Constructor. 0174 /** 0175 * This constructor creates a timer without setting an expiry time. The 0176 * expires_at() or expires_from_now() functions must be called to set an 0177 * expiry time before the timer can be waited on. 0178 * 0179 * @param context An execution context which provides the I/O executor that 0180 * the timer will use, by default, to dispatch handlers for any asynchronous 0181 * operations performed on the timer. 0182 */ 0183 template <typename ExecutionContext> 0184 explicit basic_deadline_timer(ExecutionContext& context, 0185 constraint_t< 0186 is_convertible<ExecutionContext&, execution_context&>::value 0187 > = 0) 0188 : impl_(0, 0, context) 0189 { 0190 } 0191 0192 /// Constructor to set a particular expiry time as an absolute time. 0193 /** 0194 * This constructor creates a timer and sets the expiry time. 0195 * 0196 * @param ex The I/O executor that the timer will use, by default, to 0197 * dispatch handlers for any asynchronous operations performed on the timer. 0198 * 0199 * @param expiry_time The expiry time to be used for the timer, expressed 0200 * as an absolute time. 0201 */ 0202 basic_deadline_timer(const executor_type& ex, const time_type& expiry_time) 0203 : impl_(0, ex) 0204 { 0205 boost::system::error_code ec; 0206 impl_.get_service().expires_at(impl_.get_implementation(), expiry_time, ec); 0207 boost::asio::detail::throw_error(ec, "expires_at"); 0208 } 0209 0210 /// Constructor to set a particular expiry time as an absolute time. 0211 /** 0212 * This constructor creates a timer and sets the expiry time. 0213 * 0214 * @param context An execution context which provides the I/O executor that 0215 * the timer will use, by default, to dispatch handlers for any asynchronous 0216 * operations performed on the timer. 0217 * 0218 * @param expiry_time The expiry time to be used for the timer, expressed 0219 * as an absolute time. 0220 */ 0221 template <typename ExecutionContext> 0222 basic_deadline_timer(ExecutionContext& context, const time_type& expiry_time, 0223 constraint_t< 0224 is_convertible<ExecutionContext&, execution_context&>::value 0225 > = 0) 0226 : impl_(0, 0, context) 0227 { 0228 boost::system::error_code ec; 0229 impl_.get_service().expires_at(impl_.get_implementation(), expiry_time, ec); 0230 boost::asio::detail::throw_error(ec, "expires_at"); 0231 } 0232 0233 /// Constructor to set a particular expiry time relative to now. 0234 /** 0235 * This constructor creates a timer and sets the expiry time. 0236 * 0237 * @param ex The I/O executor that the timer will use, by default, to 0238 * dispatch handlers for any asynchronous operations performed on the timer. 0239 * 0240 * @param expiry_time The expiry time to be used for the timer, relative to 0241 * now. 0242 */ 0243 basic_deadline_timer(const executor_type& ex, 0244 const duration_type& expiry_time) 0245 : impl_(0, ex) 0246 { 0247 boost::system::error_code ec; 0248 impl_.get_service().expires_from_now( 0249 impl_.get_implementation(), expiry_time, ec); 0250 boost::asio::detail::throw_error(ec, "expires_from_now"); 0251 } 0252 0253 /// Constructor to set a particular expiry time relative to now. 0254 /** 0255 * This constructor creates a timer and sets the expiry time. 0256 * 0257 * @param context An execution context which provides the I/O executor that 0258 * the timer will use, by default, to dispatch handlers for any asynchronous 0259 * operations performed on the timer. 0260 * 0261 * @param expiry_time The expiry time to be used for the timer, relative to 0262 * now. 0263 */ 0264 template <typename ExecutionContext> 0265 basic_deadline_timer(ExecutionContext& context, 0266 const duration_type& expiry_time, 0267 constraint_t< 0268 is_convertible<ExecutionContext&, execution_context&>::value 0269 > = 0) 0270 : impl_(0, 0, context) 0271 { 0272 boost::system::error_code ec; 0273 impl_.get_service().expires_from_now( 0274 impl_.get_implementation(), expiry_time, ec); 0275 boost::asio::detail::throw_error(ec, "expires_from_now"); 0276 } 0277 0278 /// Move-construct a basic_deadline_timer from another. 0279 /** 0280 * This constructor moves a timer from one object to another. 0281 * 0282 * @param other The other basic_deadline_timer object from which the move will 0283 * occur. 0284 * 0285 * @note Following the move, the moved-from object is in the same state as if 0286 * constructed using the @c basic_deadline_timer(const executor_type&) 0287 * constructor. 0288 */ 0289 basic_deadline_timer(basic_deadline_timer&& other) 0290 : impl_(std::move(other.impl_)) 0291 { 0292 } 0293 0294 /// Move-assign a basic_deadline_timer from another. 0295 /** 0296 * This assignment operator moves a timer from one object to another. Cancels 0297 * any outstanding asynchronous operations associated with the target object. 0298 * 0299 * @param other The other basic_deadline_timer object from which the move will 0300 * occur. 0301 * 0302 * @note Following the move, the moved-from object is in the same state as if 0303 * constructed using the @c basic_deadline_timer(const executor_type&) 0304 * constructor. 0305 */ 0306 basic_deadline_timer& operator=(basic_deadline_timer&& other) 0307 { 0308 impl_ = std::move(other.impl_); 0309 return *this; 0310 } 0311 0312 /// Destroys the timer. 0313 /** 0314 * This function destroys the timer, cancelling any outstanding asynchronous 0315 * wait operations associated with the timer as if by calling @c cancel. 0316 */ 0317 ~basic_deadline_timer() 0318 { 0319 } 0320 0321 /// Get the executor associated with the object. 0322 const executor_type& get_executor() noexcept 0323 { 0324 return impl_.get_executor(); 0325 } 0326 0327 /// Cancel any asynchronous operations that are waiting on the timer. 0328 /** 0329 * This function forces the completion of any pending asynchronous wait 0330 * operations against the timer. The handler for each cancelled operation will 0331 * be invoked with the boost::asio::error::operation_aborted error code. 0332 * 0333 * Cancelling the timer does not change the expiry time. 0334 * 0335 * @return The number of asynchronous operations that were cancelled. 0336 * 0337 * @throws boost::system::system_error Thrown on failure. 0338 * 0339 * @note If the timer has already expired when cancel() is called, then the 0340 * handlers for asynchronous wait operations will: 0341 * 0342 * @li have already been invoked; or 0343 * 0344 * @li have been queued for invocation in the near future. 0345 * 0346 * These handlers can no longer be cancelled, and therefore are passed an 0347 * error code that indicates the successful completion of the wait operation. 0348 */ 0349 std::size_t cancel() 0350 { 0351 boost::system::error_code ec; 0352 std::size_t s = impl_.get_service().cancel(impl_.get_implementation(), ec); 0353 boost::asio::detail::throw_error(ec, "cancel"); 0354 return s; 0355 } 0356 0357 /// Cancel any asynchronous operations that are waiting on the timer. 0358 /** 0359 * This function forces the completion of any pending asynchronous wait 0360 * operations against the timer. The handler for each cancelled operation will 0361 * be invoked with the boost::asio::error::operation_aborted error code. 0362 * 0363 * Cancelling the timer does not change the expiry time. 0364 * 0365 * @param ec Set to indicate what error occurred, if any. 0366 * 0367 * @return The number of asynchronous operations that were cancelled. 0368 * 0369 * @note If the timer has already expired when cancel() is called, then the 0370 * handlers for asynchronous wait operations will: 0371 * 0372 * @li have already been invoked; or 0373 * 0374 * @li have been queued for invocation in the near future. 0375 * 0376 * These handlers can no longer be cancelled, and therefore are passed an 0377 * error code that indicates the successful completion of the wait operation. 0378 */ 0379 std::size_t cancel(boost::system::error_code& ec) 0380 { 0381 return impl_.get_service().cancel(impl_.get_implementation(), ec); 0382 } 0383 0384 /// Cancels one asynchronous operation that is waiting on the timer. 0385 /** 0386 * This function forces the completion of one pending asynchronous wait 0387 * operation against the timer. Handlers are cancelled in FIFO order. The 0388 * handler for the cancelled operation will be invoked with the 0389 * boost::asio::error::operation_aborted error code. 0390 * 0391 * Cancelling the timer does not change the expiry time. 0392 * 0393 * @return The number of asynchronous operations that were cancelled. That is, 0394 * either 0 or 1. 0395 * 0396 * @throws boost::system::system_error Thrown on failure. 0397 * 0398 * @note If the timer has already expired when cancel_one() is called, then 0399 * the handlers for asynchronous wait operations will: 0400 * 0401 * @li have already been invoked; or 0402 * 0403 * @li have been queued for invocation in the near future. 0404 * 0405 * These handlers can no longer be cancelled, and therefore are passed an 0406 * error code that indicates the successful completion of the wait operation. 0407 */ 0408 std::size_t cancel_one() 0409 { 0410 boost::system::error_code ec; 0411 std::size_t s = impl_.get_service().cancel_one( 0412 impl_.get_implementation(), ec); 0413 boost::asio::detail::throw_error(ec, "cancel_one"); 0414 return s; 0415 } 0416 0417 /// Cancels one asynchronous operation that is waiting on the timer. 0418 /** 0419 * This function forces the completion of one pending asynchronous wait 0420 * operation against the timer. Handlers are cancelled in FIFO order. The 0421 * handler for the cancelled operation will be invoked with the 0422 * boost::asio::error::operation_aborted error code. 0423 * 0424 * Cancelling the timer does not change the expiry time. 0425 * 0426 * @param ec Set to indicate what error occurred, if any. 0427 * 0428 * @return The number of asynchronous operations that were cancelled. That is, 0429 * either 0 or 1. 0430 * 0431 * @note If the timer has already expired when cancel_one() is called, then 0432 * the handlers for asynchronous wait operations will: 0433 * 0434 * @li have already been invoked; or 0435 * 0436 * @li have been queued for invocation in the near future. 0437 * 0438 * These handlers can no longer be cancelled, and therefore are passed an 0439 * error code that indicates the successful completion of the wait operation. 0440 */ 0441 std::size_t cancel_one(boost::system::error_code& ec) 0442 { 0443 return impl_.get_service().cancel_one(impl_.get_implementation(), ec); 0444 } 0445 0446 /// Get the timer's expiry time as an absolute time. 0447 /** 0448 * This function may be used to obtain the timer's current expiry time. 0449 * Whether the timer has expired or not does not affect this value. 0450 */ 0451 time_type expires_at() const 0452 { 0453 return impl_.get_service().expires_at(impl_.get_implementation()); 0454 } 0455 0456 /// Set the timer's expiry time as an absolute time. 0457 /** 0458 * This function sets the expiry time. Any pending asynchronous wait 0459 * operations will be cancelled. The handler for each cancelled operation will 0460 * be invoked with the boost::asio::error::operation_aborted error code. 0461 * 0462 * @param expiry_time The expiry time to be used for the timer. 0463 * 0464 * @return The number of asynchronous operations that were cancelled. 0465 * 0466 * @throws boost::system::system_error Thrown on failure. 0467 * 0468 * @note If the timer has already expired when expires_at() is called, then 0469 * the handlers for asynchronous wait operations will: 0470 * 0471 * @li have already been invoked; or 0472 * 0473 * @li have been queued for invocation in the near future. 0474 * 0475 * These handlers can no longer be cancelled, and therefore are passed an 0476 * error code that indicates the successful completion of the wait operation. 0477 */ 0478 std::size_t expires_at(const time_type& expiry_time) 0479 { 0480 boost::system::error_code ec; 0481 std::size_t s = impl_.get_service().expires_at( 0482 impl_.get_implementation(), expiry_time, ec); 0483 boost::asio::detail::throw_error(ec, "expires_at"); 0484 return s; 0485 } 0486 0487 /// Set the timer's expiry time as an absolute time. 0488 /** 0489 * This function sets the expiry time. Any pending asynchronous wait 0490 * operations will be cancelled. The handler for each cancelled operation will 0491 * be invoked with the boost::asio::error::operation_aborted error code. 0492 * 0493 * @param expiry_time The expiry time to be used for the timer. 0494 * 0495 * @param ec Set to indicate what error occurred, if any. 0496 * 0497 * @return The number of asynchronous operations that were cancelled. 0498 * 0499 * @note If the timer has already expired when expires_at() is called, then 0500 * the handlers for asynchronous wait operations will: 0501 * 0502 * @li have already been invoked; or 0503 * 0504 * @li have been queued for invocation in the near future. 0505 * 0506 * These handlers can no longer be cancelled, and therefore are passed an 0507 * error code that indicates the successful completion of the wait operation. 0508 */ 0509 std::size_t expires_at(const time_type& expiry_time, 0510 boost::system::error_code& ec) 0511 { 0512 return impl_.get_service().expires_at( 0513 impl_.get_implementation(), expiry_time, ec); 0514 } 0515 0516 /// Get the timer's expiry time relative to now. 0517 /** 0518 * This function may be used to obtain the timer's current expiry time. 0519 * Whether the timer has expired or not does not affect this value. 0520 */ 0521 duration_type expires_from_now() const 0522 { 0523 return impl_.get_service().expires_from_now(impl_.get_implementation()); 0524 } 0525 0526 /// Set the timer's expiry time relative to now. 0527 /** 0528 * This function sets the expiry time. Any pending asynchronous wait 0529 * operations will be cancelled. The handler for each cancelled operation will 0530 * be invoked with the boost::asio::error::operation_aborted error code. 0531 * 0532 * @param expiry_time The expiry time to be used for the timer. 0533 * 0534 * @return The number of asynchronous operations that were cancelled. 0535 * 0536 * @throws boost::system::system_error Thrown on failure. 0537 * 0538 * @note If the timer has already expired when expires_from_now() is called, 0539 * then the handlers for asynchronous wait operations will: 0540 * 0541 * @li have already been invoked; or 0542 * 0543 * @li have been queued for invocation in the near future. 0544 * 0545 * These handlers can no longer be cancelled, and therefore are passed an 0546 * error code that indicates the successful completion of the wait operation. 0547 */ 0548 std::size_t expires_from_now(const duration_type& expiry_time) 0549 { 0550 boost::system::error_code ec; 0551 std::size_t s = impl_.get_service().expires_from_now( 0552 impl_.get_implementation(), expiry_time, ec); 0553 boost::asio::detail::throw_error(ec, "expires_from_now"); 0554 return s; 0555 } 0556 0557 /// Set the timer's expiry time relative to now. 0558 /** 0559 * This function sets the expiry time. Any pending asynchronous wait 0560 * operations will be cancelled. The handler for each cancelled operation will 0561 * be invoked with the boost::asio::error::operation_aborted error code. 0562 * 0563 * @param expiry_time The expiry time to be used for the timer. 0564 * 0565 * @param ec Set to indicate what error occurred, if any. 0566 * 0567 * @return The number of asynchronous operations that were cancelled. 0568 * 0569 * @note If the timer has already expired when expires_from_now() is called, 0570 * then the handlers for asynchronous wait operations will: 0571 * 0572 * @li have already been invoked; or 0573 * 0574 * @li have been queued for invocation in the near future. 0575 * 0576 * These handlers can no longer be cancelled, and therefore are passed an 0577 * error code that indicates the successful completion of the wait operation. 0578 */ 0579 std::size_t expires_from_now(const duration_type& expiry_time, 0580 boost::system::error_code& ec) 0581 { 0582 return impl_.get_service().expires_from_now( 0583 impl_.get_implementation(), expiry_time, ec); 0584 } 0585 0586 /// Perform a blocking wait on the timer. 0587 /** 0588 * This function is used to wait for the timer to expire. This function 0589 * blocks and does not return until the timer has expired. 0590 * 0591 * @throws boost::system::system_error Thrown on failure. 0592 */ 0593 void wait() 0594 { 0595 boost::system::error_code ec; 0596 impl_.get_service().wait(impl_.get_implementation(), ec); 0597 boost::asio::detail::throw_error(ec, "wait"); 0598 } 0599 0600 /// Perform a blocking wait on the timer. 0601 /** 0602 * This function is used to wait for the timer to expire. This function 0603 * blocks and does not return until the timer has expired. 0604 * 0605 * @param ec Set to indicate what error occurred, if any. 0606 */ 0607 void wait(boost::system::error_code& ec) 0608 { 0609 impl_.get_service().wait(impl_.get_implementation(), ec); 0610 } 0611 0612 /// Start an asynchronous wait on the timer. 0613 /** 0614 * This function may be used to initiate an asynchronous wait against the 0615 * timer. It is an initiating function for an @ref asynchronous_operation, 0616 * and always returns immediately. 0617 * 0618 * For each call to async_wait(), the completion handler will be called 0619 * exactly once. The completion handler will be called when: 0620 * 0621 * @li The timer has expired. 0622 * 0623 * @li The timer was cancelled, in which case the handler is passed the error 0624 * code boost::asio::error::operation_aborted. 0625 * 0626 * @param token The @ref completion_token that will be used to produce a 0627 * completion handler, which will be called when the timer expires. Potential 0628 * completion tokens include @ref use_future, @ref use_awaitable, @ref 0629 * yield_context, or a function object with the correct completion signature. 0630 * The function signature of the completion handler must be: 0631 * @code void handler( 0632 * const boost::system::error_code& error // Result of operation. 0633 * ); @endcode 0634 * Regardless of whether the asynchronous operation completes immediately or 0635 * not, the completion handler will not be invoked from within this function. 0636 * On immediate completion, invocation of the handler will be performed in a 0637 * manner equivalent to using boost::asio::async_immediate(). 0638 * 0639 * @par Completion Signature 0640 * @code void(boost::system::error_code) @endcode 0641 * 0642 * @par Per-Operation Cancellation 0643 * This asynchronous operation supports cancellation for the following 0644 * boost::asio::cancellation_type values: 0645 * 0646 * @li @c cancellation_type::terminal 0647 * 0648 * @li @c cancellation_type::partial 0649 * 0650 * @li @c cancellation_type::total 0651 */ 0652 template < 0653 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code)) 0654 WaitToken = default_completion_token_t<executor_type>> 0655 auto async_wait( 0656 WaitToken&& token = default_completion_token_t<executor_type>()) 0657 -> decltype( 0658 async_initiate<WaitToken, void (boost::system::error_code)>( 0659 declval<initiate_async_wait>(), token)) 0660 { 0661 return async_initiate<WaitToken, void (boost::system::error_code)>( 0662 initiate_async_wait(this), token); 0663 } 0664 0665 private: 0666 // Disallow copying and assignment. 0667 basic_deadline_timer(const basic_deadline_timer&) = delete; 0668 basic_deadline_timer& operator=( 0669 const basic_deadline_timer&) = delete; 0670 0671 class initiate_async_wait 0672 { 0673 public: 0674 typedef Executor executor_type; 0675 0676 explicit initiate_async_wait(basic_deadline_timer* self) 0677 : self_(self) 0678 { 0679 } 0680 0681 const executor_type& get_executor() const noexcept 0682 { 0683 return self_->get_executor(); 0684 } 0685 0686 template <typename WaitHandler> 0687 void operator()(WaitHandler&& handler) const 0688 { 0689 // If you get an error on the following line it means that your handler 0690 // does not meet the documented type requirements for a WaitHandler. 0691 BOOST_ASIO_WAIT_HANDLER_CHECK(WaitHandler, handler) type_check; 0692 0693 detail::non_const_lvalue<WaitHandler> handler2(handler); 0694 self_->impl_.get_service().async_wait( 0695 self_->impl_.get_implementation(), 0696 handler2.value, self_->impl_.get_executor()); 0697 } 0698 0699 private: 0700 basic_deadline_timer* self_; 0701 }; 0702 0703 detail::io_object_impl< 0704 detail::deadline_timer_service<TimeTraits>, Executor> impl_; 0705 }; 0706 0707 } // namespace asio 0708 } // namespace boost 0709 0710 #include <boost/asio/detail/pop_options.hpp> 0711 0712 #endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) 0713 // || defined(GENERATING_DOCUMENTATION) 0714 0715 #endif // !defined(BOOST_ASIO_NO_DEPRECATED) 0716 0717 #endif // BOOST_ASIO_BASIC_DEADLINE_TIMER_HPP
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |