Skip to content

Commit

Permalink
SharedPV ensure callback pairing
Browse files Browse the repository at this point in the history
Ensure that onLastDisconnect() isn't called
unless onFirstConnect() is/has been called.
  • Loading branch information
mdavidsaver committed Sep 21, 2018
1 parent a6eca51 commit 6b463d7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/server/pva/sharedstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/server/sharedstate_channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ SharedChannel::SharedChannel(const std::tr1::shared_ptr<SharedPV> &owner,
if(owner->channels.empty())
handler = owner->handler;
owner->channels.push_back(this);
owner->notifiedConn = !!handler;
}
if(handler) {
handler->onFirstConnect(owner);
Expand All @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion src/server/sharedstate_pv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ SharedPV::shared_pointer SharedPV::buildMailbox(pvas::SharedPV::Config *conf)
SharedPV::SharedPV(const std::tr1::shared_ptr<Handler> &handler, pvas::SharedPV::Config *conf)
:config(conf ? *conf : Config())
,handler(handler)
,notifiedConn(false)
,debugLvl(0)
{
REFTRACE_INCREMENT(num_instances);
Expand Down Expand Up @@ -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();
}
}
Expand Down

0 comments on commit 6b463d7

Please sign in to comment.