diff --git a/src/server/pva/sharedstate.h b/src/server/pva/sharedstate.h index 0e6ec4d5..6d6d19f7 100644 --- a/src/server/pva/sharedstate.h +++ b/src/server/pva/sharedstate.h @@ -202,6 +202,8 @@ class epicsShareClass SharedPV //! Used for initial Monitor update and Get operations. epics::pvData::BitSet valid; + bool notifiedConn; // whether onFirstConnect() has been, or is being, called + int debugLvl; EPICS_NOT_COPYABLE(SharedPV) diff --git a/src/server/sharedstate_channel.cpp b/src/server/sharedstate_channel.cpp index 1dc18fc0..b5912e79 100644 --- a/src/server/sharedstate_channel.cpp +++ b/src/server/sharedstate_channel.cpp @@ -51,6 +51,7 @@ SharedChannel::SharedChannel(const std::tr1::shared_ptr &owner, if(owner->channels.empty()) handler = owner->handler; owner->channels.push_back(this); + owner->notifiedConn = !!handler; } if(handler) { handler->onFirstConnect(owner); @@ -64,8 +65,9 @@ SharedChannel::~SharedChannel() Guard G(owner->mutex); bool wasempty = owner->channels.empty(); owner->channels.remove(this); - if(!wasempty && owner->channels.empty()) { + if(!wasempty && owner->channels.empty() && owner->notifiedConn) { handler = owner->handler; + owner->notifiedConn = false; } } if(handler) { diff --git a/src/server/sharedstate_pv.cpp b/src/server/sharedstate_pv.cpp index c0256f7e..17f45f03 100644 --- a/src/server/sharedstate_pv.cpp +++ b/src/server/sharedstate_pv.cpp @@ -74,6 +74,7 @@ SharedPV::shared_pointer SharedPV::buildMailbox(pvas::SharedPV::Config *conf) SharedPV::SharedPV(const std::tr1::shared_ptr &handler, pvas::SharedPV::Config *conf) :config(conf ? *conf : Config()) ,handler(handler) + ,notifiedConn(false) ,debugLvl(0) { REFTRACE_INCREMENT(num_instances); @@ -264,8 +265,10 @@ void SharedPV::close(bool destroy) puts.clear(); rpcs.clear(); monitors.clear(); - if(!channels.empty()) + if(!channels.empty() && notifiedConn) { p_handler = handler; + notifiedConn = false; + } channels.clear(); } }