From e52ae674ca70e6a3238623f0c94d0b71a4fb3067 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Fri, 7 Aug 2020 17:02:50 -0700 Subject: [PATCH] client: bypass search throttling during Channel creation --- src/client.cpp | 16 ++++++++++++---- src/clientimpl.h | 3 ++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/client.cpp b/src/client.cpp index 1c500ab..46aeebd 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -210,6 +210,8 @@ std::shared_ptr Channel::build(const std::shared_ptr& con context->chanByName[chan->name] = chan; context->searchBuckets[context->currentBucket].push_back(chan); + + context->poke(true); } return chan; @@ -269,7 +271,7 @@ void Context::hurryUp() throw std::logic_error("NULL Context"); pvt->manager.loop().call([this](){ - pvt->poke(); + pvt->poke(true); }); } @@ -423,12 +425,15 @@ void Context::Pvt::close() manager.sync(); } -void Context::Pvt::poke() +void Context::Pvt::poke(bool force) { + if(poked) + return; + epicsTimeStamp now{}; double age = -1.0; - if(epicsTimeGetCurrent(&now) || (age=epicsTimeDiffInSeconds(&now, &lastPoke))<30.0) { + if(!force && (epicsTimeGetCurrent(&now) || (age=epicsTimeDiffInSeconds(&now, &lastPoke))<30.0)) { log_debug_printf(setup, "Ignoring hurryUp() age=%.1f sec\n", age); return; } @@ -439,6 +444,7 @@ void Context::Pvt::poke() timeval immediate{0,0}; if(event_add(searchTimer.get(), &immediate)) throw std::runtime_error("Unable to schedule searchTimer"); + poked = true; } void Context::Pvt::onBeacon(const UDPManager::Beacon& msg) @@ -461,7 +467,7 @@ void Context::Pvt::onBeacon(const UDPManager::Beacon& msg) guid[0], guid[1], guid[2], guid[3], guid[4], guid[5], guid[6], guid[7], guid[8], guid[9], guid[10], guid[11], msg.server.tostring().c_str()); - poke(); + poke(false); } bool Context::Pvt::onSearch() @@ -617,6 +623,8 @@ void Context::Pvt::onSearchS(evutil_socket_t fd, short evt, void *raw) void Context::Pvt::tickSearch() { + poked = false; + auto idx = currentBucket; currentBucket = (currentBucket+1u)%searchBuckets.size(); diff --git a/src/clientimpl.h b/src/clientimpl.h index 8847da4..d5ae66b 100644 --- a/src/clientimpl.h +++ b/src/clientimpl.h @@ -186,6 +186,7 @@ struct Context::Pvt uint16_t searchRxPort; epicsTimeStamp lastPoke{}; + bool poked = false; std::vector searchMsg; @@ -228,7 +229,7 @@ struct Context::Pvt void close(); - void poke(); + void poke(bool force); void onBeacon(const UDPManager::Beacon& msg);