From 1a4e6e8d32c811cc0dee45f63c7c1462665d5c27 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Fri, 21 Feb 2020 08:01:29 -0800 Subject: [PATCH] hurryUp() --- src/client.cpp | 26 ++++++++++++++++++++++++-- src/clientimpl.h | 6 ++++++ src/pvxs/client.h | 2 +- tools/info.cpp | 3 +++ 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/client.cpp b/src/client.cpp index 7f311c0..fba7a67 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -137,8 +137,12 @@ const Config& Context::config() const return pvt->effective; } -void Context::poke() -{} +void Context::hurryUp() +{ + pvt->tcp_loop.call([this](){ + pvt->poke(); + }); +} static Value buildCAMethod() @@ -251,6 +255,24 @@ void Context::Pvt::close() }); } +void Context::Pvt::poke() +{ + epicsTimeStamp now{}; + + double age = -1.0; + if(epicsTimeGetCurrent(&now) || (age=epicsTimeDiffInSeconds(&now, &lastPoke))<30.0) { + log_debug_printf(setup, "Ignoring hurryUp() age=%.1f sec\n", age); + return; + } + lastPoke = now; + + log_debug_printf(setup, "hurryUp()%s\n", ""); + + timeval immediate{0,0}; + if(event_add(searchTimer.get(), &immediate)) + throw std::runtime_error("Unable to schedule searchTimer"); +} + bool Context::Pvt::onSearch() { searchMsg.resize(0x10000); diff --git a/src/clientimpl.h b/src/clientimpl.h index 2c53f1a..6ffb7d3 100644 --- a/src/clientimpl.h +++ b/src/clientimpl.h @@ -8,6 +8,8 @@ #include +#include + #include #include "evhelper.h" @@ -133,6 +135,8 @@ struct Context::Pvt evsocket searchTx; uint16_t searchRxPort; + epicsTimeStamp lastPoke{}; + std::vector searchMsg; // search destination address and whether to set the unicast flag @@ -157,6 +161,8 @@ struct Context::Pvt void close(); + void poke(); + bool onSearch(); static void onSearchS(evutil_socket_t fd, short evt, void *raw); void tickSearch(); diff --git a/src/pvxs/client.h b/src/pvxs/client.h index adf2de4..05e7517 100644 --- a/src/pvxs/client.h +++ b/src/pvxs/client.h @@ -98,7 +98,7 @@ public: const Config& config() const; //! Request prompt search of any disconnected channels - void poke(); + void hurryUp(); Request request() const; diff --git a/tools/info.cpp b/tools/info.cpp index 09ad125..4baedd8 100644 --- a/tools/info.cpp +++ b/tools/info.cpp @@ -82,6 +82,9 @@ int main(int argc, char *argv[]) .exec()); } + // expedite search after starting all requests + ctxt.hurryUp(); + SigInt sig([&done]() { done.signal(); });