New asio api: removed unnecessary SimpleWeb::timer_expires_after

This commit is contained in:
eidheim 2019-05-20 18:39:54 +02:00
commit 44c2f733dc
3 changed files with 3 additions and 19 deletions

View file

@ -25,7 +25,7 @@ namespace SimpleWeb {
#endif #endif
namespace SimpleWeb { namespace SimpleWeb {
#if(USE_STANDALONE_ASIO && ASIO_VERSION >= 101300) || BOOST_ASIO_VERSION >= 101300 // TODO: change to 101300 #if(USE_STANDALONE_ASIO && ASIO_VERSION >= 101300) || BOOST_ASIO_VERSION >= 101300
using io_context = asio::io_context; using io_context = asio::io_context;
using resolver_results = asio::ip::tcp::resolver::results_type; using resolver_results = asio::ip::tcp::resolver::results_type;
using async_connect_endpoint = asio::ip::tcp::endpoint; using async_connect_endpoint = asio::ip::tcp::endpoint;
@ -33,9 +33,6 @@ namespace SimpleWeb {
inline void restart(io_context &context) noexcept { inline void restart(io_context &context) noexcept {
context.restart(); context.restart();
} }
inline void timer_expires_after(asio::steady_timer &timer, const asio::steady_timer::duration &duration) {
timer.expires_after(duration);
}
inline asio::ip::address make_address(const std::string &str) noexcept { inline asio::ip::address make_address(const std::string &str) noexcept {
return asio::ip::make_address(str); return asio::ip::make_address(str);
} }
@ -63,9 +60,6 @@ namespace SimpleWeb {
inline void restart(io_context &context) noexcept { inline void restart(io_context &context) noexcept {
context.reset(); context.reset();
} }
inline void timer_expires_after(asio::steady_timer &timer, const asio::steady_timer::duration &duration) {
timer.expires_from_now(duration);
}
inline asio::ip::address make_address(const std::string &str) noexcept { inline asio::ip::address make_address(const std::string &str) noexcept {
return asio::ip::address::from_string(str); return asio::ip::address::from_string(str);
} }

View file

@ -99,12 +99,7 @@ namespace SimpleWeb {
timer = nullptr; timer = nullptr;
return; return;
} }
timer = std::unique_ptr<asio::steady_timer>(new asio::steady_timer(get_socket_context(*socket))); timer = std::unique_ptr<asio::steady_timer>(new asio::steady_timer(get_socket_context(*socket), std::chrono::seconds(seconds)));
try {
timer_expires_after(*timer, std::chrono::seconds(seconds));
}
catch(...) {
}
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) {

View file

@ -278,12 +278,7 @@ namespace SimpleWeb {
return; return;
} }
timer = std::unique_ptr<asio::steady_timer>(new asio::steady_timer(get_socket_context(*socket))); timer = std::unique_ptr<asio::steady_timer>(new asio::steady_timer(get_socket_context(*socket), std::chrono::seconds(seconds)));
try {
timer_expires_after(*timer, std::chrono::seconds(seconds));
}
catch(...) {
}
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)