diff options
author | Riccardo Spagni <ric@spagni.net> | 2017-07-03 12:51:00 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2017-07-03 12:51:00 +0200 |
commit | 605ad09a3e8708fb90f4236df8eb20e0631a06a2 (patch) | |
tree | 31d750c045c23a0bc9a4377d70ad471454dd2db1 /contrib/epee | |
parent | Merge pull request #2127 (diff) | |
parent | Fix issue #2119 SEGV (diff) | |
download | monero-605ad09a3e8708fb90f4236df8eb20e0631a06a2.tar.xz |
Merge pull request #2130
a0d2c745 Fix issue #2119 SEGV (Howard Chu)
Diffstat (limited to 'contrib/epee')
-rw-r--r-- | contrib/epee/include/net/levin_protocol_handler_async.h | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/contrib/epee/include/net/levin_protocol_handler_async.h b/contrib/epee/include/net/levin_protocol_handler_async.h index 5ef782206..8aa0faba1 100644 --- a/contrib/epee/include/net/levin_protocol_handler_async.h +++ b/contrib/epee/include/net/levin_protocol_handler_async.h @@ -144,7 +144,6 @@ public: virtual void cancel()=0; virtual bool cancel_timer()=0; virtual void reset_timer()=0; - virtual void timeout_handler(const boost::system::error_code& error)=0; }; template <class callback_t> struct anvoke_handler: invoke_response_handler_base @@ -157,9 +156,15 @@ public: { MDEBUG(con.get_context_ref() << "anvoke_handler, timeout: " << timeout); m_timer.expires_from_now(boost::posix_time::milliseconds(timeout)); - m_timer.async_wait([this](const boost::system::error_code& ec) + m_timer.async_wait([&con, command, cb, timeout](const boost::system::error_code& ec) { - timeout_handler(ec); + if(ec == boost::asio::error::operation_aborted) + return; + MINFO(con.get_context_ref() << "Timeout on invoke operation happened, command: " << command << " timeout: " << timeout); + std::string fake; + cb(LEVIN_ERROR_CONNECTION_TIMEDOUT, fake, con.get_context_ref()); + con.close(); + con.finish_outer_call(); }); m_timer_started = true; } @@ -174,16 +179,6 @@ public: bool m_timer_cancelled; uint64_t m_timeout; int m_command; - virtual void timeout_handler(const boost::system::error_code& error) - { - if(error == boost::asio::error::operation_aborted) - return; - MINFO(m_con.get_context_ref() << "Timeout on invoke operation happened, command: " << m_command << " timeout: " << m_timeout); - std::string fake; - m_cb(LEVIN_ERROR_CONNECTION_TIMEDOUT, fake, m_con.get_context_ref()); - m_con.close(); - m_con.finish_outer_call(); - } virtual bool handle(int res, const std::string& buff, typename async_protocol_handler::connection_context& context) { if(!cancel_timer()) @@ -220,10 +215,20 @@ public: boost::system::error_code ignored_ec; if (!m_cancel_timer_called && m_timer.cancel(ignored_ec) > 0) { + callback_t& cb = m_cb; + uint64_t timeout = m_timeout; + async_protocol_handler& con = m_con; + int command = m_command; m_timer.expires_from_now(boost::posix_time::milliseconds(m_timeout)); - m_timer.async_wait([this](const boost::system::error_code& ec) + m_timer.async_wait([&con, cb, command, timeout](const boost::system::error_code& ec) { - timeout_handler(ec); + if(ec == boost::asio::error::operation_aborted) + return; + MINFO(con.get_context_ref() << "Timeout on invoke operation happened, command: " << command << " timeout: " << timeout); + std::string fake; + cb(LEVIN_ERROR_CONNECTION_TIMEDOUT, fake, con.get_context_ref()); + con.close(); + con.finish_outer_call(); }); } } |