2
0
mirror of https://github.com/boostorg/asio.git synced 2026-01-30 19:32:09 +00:00

Update examples to use chrono rather than Boost.Date_Time.

N.B. The Windows-specific tick_count_timer example has been removed as
it has been superseded by timers based on the standard steady_clock.
It's also not clear how to map a wrapping time source to the standard
chrono concepts.
This commit is contained in:
Christopher Kohlhoff
2018-04-01 09:58:45 +10:00
parent 5672713c90
commit 69d54db71f
15 changed files with 111 additions and 244 deletions

View File

@@ -8,10 +8,10 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/asio/deadline_timer.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/asio/steady_timer.hpp>
#include <boost/asio/write.hpp>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
@@ -53,7 +53,7 @@ private:
char data[128];
for (;;)
{
timer_.expires_from_now(boost::posix_time::seconds(10));
timer_.expires_after(boost::asio::chrono::seconds(10));
std::size_t n = socket_.async_read_some(boost::asio::buffer(data), yield);
boost::asio::async_write(socket_, boost::asio::buffer(data, n), yield);
}
@@ -71,14 +71,14 @@ private:
{
boost::system::error_code ignored_ec;
timer_.async_wait(yield[ignored_ec]);
if (timer_.expires_from_now() <= boost::posix_time::seconds(0))
if (timer_.expiry() <= boost::asio::steady_timer::clock_type::now())
socket_.close();
}
}
boost::asio::io_context::strand strand_;
tcp::socket socket_;
boost::asio::deadline_timer timer_;
boost::asio::steady_timer timer_;
};
void do_accept(boost::asio::io_context& io_context,