File: timers.qbk

package info (click to toggle)
boost1.55 1.55.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 487,824 kB
  • ctags: 673,349
  • sloc: cpp: 2,098,430; xml: 106,036; ansic: 46,744; python: 32,427; sh: 11,864; cs: 2,121; asm: 1,640; makefile: 984; perl: 714; yacc: 456; php: 132; fortran: 43; sql: 13; csh: 6
file content (53 lines) | stat: -rw-r--r-- 1,574 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
[/
 / Copyright (c) 2003-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com)
 /
 / Distributed under the Boost Software License, Version 1.0. (See accompanying
 / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 /]

[section:timers Timers]

Long running I/O operations will often have a deadline by which they must have
completed. These deadlines may be expressed as absolute times, but are often
calculated relative to the current time.

As a simple example, to perform a synchronous wait operation on a timer using a
relative time one may write:

  io_service i;
  ...
  deadline_timer t(i);
  t.expires_from_now(boost::posix_time::seconds(5));
  t.wait();

More commonly, a program will perform an asynchronous wait operation on a
timer:

  void handler(boost::system::error_code ec) { ... }
  ...
  io_service i;
  ...
  deadline_timer t(i);
  t.expires_from_now(boost::posix_time::milliseconds(400));
  t.async_wait(handler);
  ...
  i.run();

The deadline associated with a timer may also be obtained as a relative time:

  boost::posix_time::time_duration time_until_expiry
    = t.expires_from_now();

or as an absolute time to allow composition of timers:

  deadline_timer t2(i);
  t2.expires_at(t.expires_at() + boost::posix_time::seconds(30));

[heading See Also]

[link boost_asio.reference.basic_deadline_timer basic_deadline_timer],
[link boost_asio.reference.deadline_timer deadline_timer],
[link boost_asio.reference.deadline_timer_service deadline_timer_service],
[link boost_asio.tutorial.tuttimer1 timer tutorials].

[endsect]