diff --git a/src/ripple_app/paths/PathRequest.cpp b/src/ripple_app/paths/PathRequest.cpp index 86c6ef70f..e24d5936a 100644 --- a/src/ripple_app/paths/PathRequest.cpp +++ b/src/ripple_app/paths/PathRequest.cpp @@ -74,6 +74,12 @@ bool PathRequest::isValid () return bValid; } +bool PathRequest::isNew () +{ + // does this path request still need its first full path + return iLastIndex.load() == 0; +} + bool PathRequest::needsUpdate (bool newOnly, LedgerIndex index) { LedgerIndex lastIndex = iLastIndex.load(); diff --git a/src/ripple_app/paths/PathRequest.h b/src/ripple_app/paths/PathRequest.h index ae63a4e21..f1ea4cec8 100644 --- a/src/ripple_app/paths/PathRequest.h +++ b/src/ripple_app/paths/PathRequest.h @@ -53,6 +53,7 @@ public: bool isValid (const boost::shared_ptr&); bool isValid (); + bool isNew (); bool needsUpdate (bool newOnly, LedgerIndex index); Json::Value getStatus (); diff --git a/src/ripple_app/paths/PathRequests.cpp b/src/ripple_app/paths/PathRequests.cpp index a03bb6673..38273e475 100644 --- a/src/ripple_app/paths/PathRequests.cpp +++ b/src/ripple_app/paths/PathRequests.cpp @@ -67,23 +67,6 @@ void PathRequests::updateAll (Ledger::ref inLedger, CancelCallback shouldCancel) do { - { // Get the latest requests, cache, and ledger - ScopedLockType sl (mLock, __FILE__, __LINE__); - - if (mRequests.empty()) - return; - - // Newest request is last in mRequests, but we want to serve it first - requests.empty(); - requests.reserve (mRequests.size ()); - BOOST_REVERSE_FOREACH (PathRequest::wptr& req, mRequests) - { - requests.push_back (req); - } - - cache = getLineCache (ledger, false); - } - BOOST_FOREACH (PathRequest::wref wRequest, requests) { if (shouldCancel()) @@ -152,6 +135,17 @@ void PathRequests::updateAll (Ledger::ref inLedger, CancelCallback shouldCancel) return; } + { + // Get the latest requests, cache, and ledger for next pass + ScopedLockType sl (mLock, __FILE__, __LINE__); + + if (mRequests.empty()) + break; + requests = mRequests; + + cache = getLineCache (ledger, false); + } + } while (!shouldCancel ()); @@ -182,7 +176,20 @@ Json::Value PathRequests::makePathRequest( { { ScopedLockType sl (mLock, __FILE__, __LINE__); - mRequests.push_back (req); + + // Insert after any older unserviced requests but before any serviced requests + std::vector::iterator it = mRequests.begin (); + while (it != mRequests.end ()) + { + PathRequest::pointer req = it->lock (); + if (req && !req->isNew ()) + break; // This request has been handled, we come before it + + // This is a newer request, we come after it + ++it; + } + mRequests.insert (it, PathRequest::wptr (req)); + } subscriber->setPathRequest (req); getApp().getLedgerMaster().newPathRequest();