summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/asio/src/examples/cpp03/icmp/ping.cpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/asio/src/examples/cpp03/icmp/ping.cpp')
-rw-r--r--3rdparty/asio/src/examples/cpp03/icmp/ping.cpp26
1 files changed, 14 insertions, 12 deletions
diff --git a/3rdparty/asio/src/examples/cpp03/icmp/ping.cpp b/3rdparty/asio/src/examples/cpp03/icmp/ping.cpp
index 3a1d278415d..7830560e4ca 100644
--- a/3rdparty/asio/src/examples/cpp03/icmp/ping.cpp
+++ b/3rdparty/asio/src/examples/cpp03/icmp/ping.cpp
@@ -2,14 +2,14 @@
// ping.cpp
// ~~~~~~~~
//
-// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+// Copyright (c) 2003-2021 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)
//
#include <asio.hpp>
-#include <boost/bind.hpp>
+#include <boost/bind/bind.hpp>
#include <istream>
#include <iostream>
#include <ostream>
@@ -18,8 +18,8 @@
#include "ipv4_header.hpp"
using asio::ip::icmp;
-using asio::deadline_timer;
-namespace posix_time = boost::posix_time;
+using asio::steady_timer;
+namespace chrono = asio::chrono;
class pinger
{
@@ -53,12 +53,12 @@ private:
os << echo_request << body;
// Send the request.
- time_sent_ = posix_time::microsec_clock::universal_time();
+ time_sent_ = steady_timer::clock_type::now();
socket_.send_to(request_buffer.data(), destination_);
// Wait up to five seconds for a reply.
num_replies_ = 0;
- timer_.expires_at(time_sent_ + posix_time::seconds(5));
+ timer_.expires_at(time_sent_ + chrono::seconds(5));
timer_.async_wait(boost::bind(&pinger::handle_timeout, this));
}
@@ -68,7 +68,7 @@ private:
std::cout << "Request timed out" << std::endl;
// Requests must be sent no less than one second apart.
- timer_.expires_at(time_sent_ + posix_time::seconds(1));
+ timer_.expires_at(time_sent_ + chrono::seconds(1));
timer_.async_wait(boost::bind(&pinger::start_send, this));
}
@@ -79,7 +79,7 @@ private:
// Wait for a reply. We prepare the buffer to receive up to 64KB.
socket_.async_receive(reply_buffer_.prepare(65536),
- boost::bind(&pinger::handle_receive, this, _2));
+ boost::bind(&pinger::handle_receive, this, boost::placeholders::_2));
}
void handle_receive(std::size_t length)
@@ -106,12 +106,14 @@ private:
timer_.cancel();
// Print out some information about the reply packet.
- posix_time::ptime now = posix_time::microsec_clock::universal_time();
+ chrono::steady_clock::time_point now = chrono::steady_clock::now();
+ chrono::steady_clock::duration elapsed = now - time_sent_;
std::cout << length - ipv4_hdr.header_length()
<< " bytes from " << ipv4_hdr.source_address()
<< ": icmp_seq=" << icmp_hdr.sequence_number()
<< ", ttl=" << ipv4_hdr.time_to_live()
- << ", time=" << (now - time_sent_).total_milliseconds() << " ms"
+ << ", time="
+ << chrono::duration_cast<chrono::milliseconds>(elapsed).count()
<< std::endl;
}
@@ -130,9 +132,9 @@ private:
icmp::resolver resolver_;
icmp::endpoint destination_;
icmp::socket socket_;
- deadline_timer timer_;
+ steady_timer timer_;
unsigned short sequence_number_;
- posix_time::ptime time_sent_;
+ chrono::steady_clock::time_point time_sent_;
asio::streambuf reply_buffer_;
std::size_t num_replies_;
};