diff --git a/src/ca/cac.cpp b/src/ca/cac.cpp index d1db2a806..7d1e78da0 100644 --- a/src/ca/cac.cpp +++ b/src/ca/cac.cpp @@ -770,7 +770,7 @@ netSubscription & cac::subscriptionRequest ( this->ioTable.add ( *pIO ); if ( chan.connected ( guard ) ) { this->flushIfRequired ( guard, *chan.getPIIU(guard) ); - chan.getPIIU(guard)->subscriptionRequest ( guard, chan, *pIO ); + pIO->subscribeIfRequired ( guard, chan ); } return *pIO.release (); } diff --git a/src/ca/nciu.cpp b/src/ca/nciu.cpp index 84633c54e..667e633f3 100644 --- a/src/ca/nciu.cpp +++ b/src/ca/nciu.cpp @@ -542,7 +542,7 @@ void nciu::resubscribe ( epicsGuard < epicsMutex > & guard ) // them here. if ( pSubscr ) { try { - this->getPIIU(guard)->subscriptionRequest ( guard, *this, *pSubscr ); + pSubscr->subscribeIfRequired ( guard, *this ); } catch ( ... ) { errlogPrintf ( "CAC: failed to send subscription request " diff --git a/src/ca/netSubscription.cpp b/src/ca/netSubscription.cpp index c69458e13..2ffaec1e5 100644 --- a/src/ca/netSubscription.cpp +++ b/src/ca/netSubscription.cpp @@ -37,7 +37,7 @@ netSubscription::netSubscription ( unsigned maskIn, cacStateNotify & notifyIn ) : count ( countIn ), privateChanForIO ( chanIn ), notify ( notifyIn ), type ( typeIn ), mask ( maskIn ), - updateWhileDisconnected ( false ) + updateWhileDisconnected ( false ), subscribed ( false ) { if ( ! dbr_type_is_valid ( typeIn ) ) { throw cacChannel::badType (); @@ -93,6 +93,9 @@ void netSubscription::exception ( epicsGuard < epicsMutex > & guard, cacRecycle & recycle, int status, const char * pContext ) { + if ( status == ECA_DISCONN ) { + this->subscribed = false; + } if ( status == ECA_CHANDESTROY ) { this->notify.exception ( guard, status, pContext, UINT_MAX, 0 ); @@ -118,6 +121,9 @@ void netSubscription::exception ( cacRecycle & recycle, int status, const char * pContext, unsigned typeIn, arrayElementCount countIn ) { + if ( status == ECA_DISCONN ) { + this->subscribed = false; + } if ( status == ECA_CHANDESTROY ) { this->notify.exception ( guard, status, pContext, UINT_MAX, 0 ); @@ -154,6 +160,16 @@ void netSubscription::completion ( } } +void netSubscription::subscribeIfRequired ( + epicsGuard < epicsMutex > & guard, nciu & chan ) +{ + if ( ! this->subscribed ) { + chan.getPIIU(guard)->subscriptionRequest ( + guard, chan, *this ); + this->subscribed = true; + } +} + void netSubscription::subscriptionUpdateIfRequired ( epicsGuard < epicsMutex > & guard, nciu & chan ) {