Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / asio / basic_waitable_timer.hpp @ 2486

History | View | Annotate | Download (18.1 kB)

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