Merge branch 'master' of github.com:jedmccaleb/NewCoin

This commit is contained in:
Arthur Britto
2012-05-13 11:59:24 -07:00
2 changed files with 12 additions and 9 deletions

View File

@@ -56,13 +56,13 @@ void PeerSet::badPeer(Peer::pointer ptr)
void PeerSet::resetTimer()
{
mTimer.expires_from_now(boost::posix_time::seconds(mTimerInterval));
mTimer.async_wait(getTimerLamba());
mTimer.async_wait(boost::bind(&PeerSet::TimerEntry, pmDowncast(), boost::asio::placeholders::error));
}
void LedgerAcquire::LATimerEntry(boost::weak_ptr<LedgerAcquire> wptr, const boost::system::error_code& result)
void PeerSet::TimerEntry(boost::weak_ptr<PeerSet> wptr, const boost::system::error_code& result)
{
if (result == boost::asio::error::operation_aborted) return;
boost::shared_ptr<LedgerAcquire> ptr = wptr.lock();
boost::shared_ptr<PeerSet> ptr = wptr.lock();
if (!!ptr) ptr->onTimer();
}
@@ -74,10 +74,9 @@ LedgerAcquire::LedgerAcquire(const uint256& hash) : PeerSet(hash, LEDGER_ACQUIRE
#endif
}
boost::function<void (boost::system::error_code)> LedgerAcquire::getTimerLamba()
boost::weak_ptr<PeerSet> LedgerAcquire::pmDowncast()
{
return boost::bind(&LedgerAcquire::LATimerEntry, boost::weak_ptr<LedgerAcquire>(shared_from_this()),
boost::asio::placeholders::error);
return boost::shared_polymorphic_downcast<PeerSet, LedgerAcquire>(shared_from_this());
}
void LedgerAcquire::done()

View File

@@ -37,10 +37,14 @@ public:
protected:
virtual void newPeer(Peer::pointer) = 0;
virtual boost::function<void (boost::system::error_code)> getTimerLamba() = 0;
virtual void onTimer(void) = 0;
virtual boost::weak_ptr<PeerSet> pmDowncast() = 0;
void setComplete() { mComplete = true; }
void setFailed() { mFailed = true; }
private:
static void TimerEntry(boost::weak_ptr<PeerSet>, const boost::system::error_code& result);
};
class LedgerAcquire : public PeerSet, public boost::enable_shared_from_this<LedgerAcquire>
@@ -61,8 +65,8 @@ protected:
void sendRequest(boost::shared_ptr<newcoin::TMGetLedger> message, Peer::pointer peer);
void newPeer(Peer::pointer peer) { trigger(peer); }
void trigger(Peer::pointer);
virtual boost::function<void (boost::system::error_code)> getTimerLamba();
static void LATimerEntry(boost::weak_ptr<LedgerAcquire>, const boost::system::error_code&);
boost::weak_ptr<PeerSet> pmDowncast();
public:
LedgerAcquire(const uint256& hash);