Completed PR #153: using steady timer instead of deadline timer to remove boost dependency when using standalone asio
This commit is contained in:
parent
28803d81be
commit
f7ddeeda82
2 changed files with 6 additions and 4 deletions
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#ifdef USE_STANDALONE_ASIO
|
#ifdef USE_STANDALONE_ASIO
|
||||||
#include <asio.hpp>
|
#include <asio.hpp>
|
||||||
|
#include <asio/steady_timer.hpp>
|
||||||
namespace SimpleWeb {
|
namespace SimpleWeb {
|
||||||
using error_code = std::error_code;
|
using error_code = std::error_code;
|
||||||
using errc = std::errc;
|
using errc = std::errc;
|
||||||
|
|
@ -18,6 +19,7 @@ namespace SimpleWeb {
|
||||||
} // namespace SimpleWeb
|
} // namespace SimpleWeb
|
||||||
#else
|
#else
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
|
#include <boost/asio/steady_timer.hpp>
|
||||||
#include <boost/utility/string_ref.hpp>
|
#include <boost/utility/string_ref.hpp>
|
||||||
namespace SimpleWeb {
|
namespace SimpleWeb {
|
||||||
namespace asio = boost::asio;
|
namespace asio = boost::asio;
|
||||||
|
|
@ -106,7 +108,7 @@ namespace SimpleWeb {
|
||||||
bool in_use = false;
|
bool in_use = false;
|
||||||
bool attempt_reconnect = true;
|
bool attempt_reconnect = true;
|
||||||
|
|
||||||
std::unique_ptr<asio::deadline_timer> timer;
|
std::unique_ptr<asio::steady_timer> timer;
|
||||||
|
|
||||||
void set_timeout(long seconds = 0) noexcept {
|
void set_timeout(long seconds = 0) noexcept {
|
||||||
if(seconds == 0)
|
if(seconds == 0)
|
||||||
|
|
@ -115,8 +117,8 @@ namespace SimpleWeb {
|
||||||
timer = nullptr;
|
timer = nullptr;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
timer = std::unique_ptr<asio::deadline_timer>(new asio::deadline_timer(socket->get_io_service()));
|
timer = std::unique_ptr<asio::steady_timer>(new asio::steady_timer(socket->get_io_service()));
|
||||||
timer->expires_from_now(boost::posix_time::seconds(seconds));
|
timer->expires_from_now(std::chrono::seconds(seconds));
|
||||||
auto self = this->shared_from_this();
|
auto self = this->shared_from_this();
|
||||||
timer->async_wait([self](const error_code &ec) {
|
timer->async_wait([self](const error_code &ec) {
|
||||||
if(!ec) {
|
if(!ec) {
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
#ifdef USE_STANDALONE_ASIO
|
#ifdef USE_STANDALONE_ASIO
|
||||||
#include <asio.hpp>
|
#include <asio.hpp>
|
||||||
#include <asio/basic_waitable_timer.hpp>
|
#include <asio/steady_timer.hpp>
|
||||||
namespace SimpleWeb {
|
namespace SimpleWeb {
|
||||||
using error_code = std::error_code;
|
using error_code = std::error_code;
|
||||||
using errc = std::errc;
|
using errc = std::errc;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue