Browse Source

Merge pull request #2537 from gluk256/_bugfix_tests

bugfix: reap() refactored
cl-refactor
Gav Wood 9 years ago
parent
commit
60bfd8c794
  1. 23
      libp2p/Common.cpp
  2. 9
      libp2p/Common.h

23
libp2p/Common.cpp

@ -176,6 +176,29 @@ void NodeIPEndpoint::interpretRLP(RLP const& _r)
tcpPort = _r[2].toInt<uint16_t>();
}
void DeadlineOps::reap()
{
if (m_stopped)
return;
Guard l(x_timers);
std::vector<DeadlineOp>::iterator t = m_timers.begin();
while (t != m_timers.end())
if (t->expired())
{
t->wait();
t = m_timers.erase(t);
}
else
t++;
m_timers.emplace_back(m_io, m_reapIntervalMs, [this](boost::system::error_code const& ec)
{
if (!ec && !m_stopped)
reap();
});
}
namespace dev {
std::ostream& operator<<(std::ostream& _out, dev::p2p::NodeIPEndpoint const& _ep)

9
libp2p/Common.h

@ -237,14 +237,13 @@ class DeadlineOps
public:
DeadlineOps(ba::io_service& _io, unsigned _reapIntervalMs = 100): m_io(_io), m_reapIntervalMs(_reapIntervalMs), m_stopped(false) { reap(); }
~DeadlineOps() { stop(); }
void schedule(unsigned _msInFuture, std::function<void(boost::system::error_code const&)> const& _f) { if (m_stopped) return; DEV_GUARDED(x_timers) m_timers.emplace_back(m_io, _msInFuture, _f); }
void schedule(unsigned _msInFuture, std::function<void(boost::system::error_code const&)> const& _f) { if (m_stopped) return; DEV_GUARDED(x_timers) m_timers.emplace_back(m_io, _msInFuture, _f); }
void stop() { m_stopped = true; DEV_GUARDED(x_timers) m_timers.clear(); }
protected:
void reap() { Guard l(x_timers); auto t = m_timers.begin(); while (t != m_timers.end()) if (t->expired()) { t->wait(); m_timers.erase(t); } else t++; m_timers.emplace_back(m_io, m_reapIntervalMs, [this](boost::system::error_code const& ec){ if (!ec) reap(); }); }
void reap();
private:
ba::io_service& m_io;
unsigned m_reapIntervalMs;

Loading…
Cancel
Save