From 6a46e44da9712cb03aab779a20073e80cf5a4f76 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Fri, 31 Jul 2020 15:36:01 -0700 Subject: [PATCH] fix SharedPV onLastDisconnect when not open() --- src/sharedpv.cpp | 6 ++---- test/testrpc.cpp | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/sharedpv.cpp b/src/sharedpv.cpp index 77354ad..6ee7017 100644 --- a/src/sharedpv.cpp +++ b/src/sharedpv.cpp @@ -370,10 +370,8 @@ void SharedPV::close() { Guard G(impl->lock); - if(!impl->current) - return; // ignore double close() - - impl->current = Value(); + if(impl->current) + impl->current = Value(); impl->subscribers.clear(); channels = std::move(impl->channels); diff --git a/test/testrpc.cpp b/test/testrpc.cpp index cf1e34b..e3e0386 100644 --- a/test/testrpc.cpp +++ b/test/testrpc.cpp @@ -109,6 +109,20 @@ struct Tester { // mbox not open serv.start(); + std::atomic onFC{false}, onLD{false}; + epicsEvent fldone; + + mbox.onFirstConnect([&onFC](server::SharedPV&){ + testShow()<<"In onFirstConnect()"; + + onFC.store(true); + }); + mbox.onLastDisconnect([&onLD, &fldone](server::SharedPV&){ + testShow()<<"In onLastDisconnect"; + onLD.store(true); + fldone.signal(); + }); + auto arg = initial.cloneEmpty(); arg["value"] = 42; auto op = doCall(std::move(arg)); @@ -118,6 +132,14 @@ struct Tester { testOk1(!!ret["value"].as(v)); testEq(v, 42); } + + op.reset(); + cli.cacheClear(); + testOk1(fldone.wait(5.0)); + + testOk1(!mbox.isOpen()); + testOk1(!!onFC.load()); + testOk1(!!onLD.load()); } void null() @@ -218,7 +240,7 @@ struct Tester { MAIN(testrpc) { - testPlan(16); + testPlan(20); testSetup(); Tester().echo(); Tester().lazy();