| 1 | #include <iostream>
|
|---|
| 2 |
|
|---|
| 3 | #include <boost/asio/io_service.hpp>
|
|---|
| 4 | #include <boost/asio/steady_timer.hpp>
|
|---|
| 5 | #include <boost/chrono.hpp>
|
|---|
| 6 | #include <boost/thread.hpp>
|
|---|
| 7 |
|
|---|
| 8 | boost::asio::io_service io_service;
|
|---|
| 9 | boost::asio::steady_timer timer(io_service);
|
|---|
| 10 |
|
|---|
| 11 | void arm_timer()
|
|---|
| 12 | {
|
|---|
| 13 | std::cout << ".";
|
|---|
| 14 | std::cout.flush();
|
|---|
| 15 | timer.expires_from_now(boost::chrono::seconds(3));
|
|---|
| 16 | timer.async_wait(boost::bind(&arm_timer));
|
|---|
| 17 | }
|
|---|
| 18 |
|
|---|
| 19 | int main()
|
|---|
| 20 | {
|
|---|
| 21 | // Add asynchronous work loop.
|
|---|
| 22 | arm_timer();
|
|---|
| 23 |
|
|---|
| 24 | boost::thread poll_thread(
|
|---|
| 25 | boost::bind(&boost::asio::io_service::poll, boost::ref(io_service)));
|
|---|
| 26 |
|
|---|
| 27 | // Give time for poll thread service reactor.
|
|---|
| 28 | boost::this_thread::sleep_for(boost::chrono::seconds(1));
|
|---|
| 29 |
|
|---|
| 30 | io_service.run();
|
|---|
| 31 | }
|
|---|