diff --git a/src/ca/tcpiiu.cpp b/src/ca/tcpiiu.cpp index a600e36fb..fabde268c 100644 --- a/src/ca/tcpiiu.cpp +++ b/src/ca/tcpiiu.cpp @@ -357,9 +357,9 @@ extern "C" void cacRecvThreadTCP ( void *pParam ) pComBuf->destroy (); } - piiu->pCAC()->uninstallIIU ( *piiu ); + piiu->stopThreads (); - piiu->destroy (); + piiu->pCAC()->uninstallIIU ( *piiu ); } // @@ -618,16 +618,13 @@ void tcpiiu::shutdown ( bool discardPendingMessages ) } } -// -// tcpiiu::~tcpiiu () -// -tcpiiu::~tcpiiu () +void tcpiiu::stopThreads () { + this->cleanShutdown (); + this->sendDog.cancel (); this->recvDog.cancel (); - this->cleanShutdown (); - // wait for send thread to exit static const double shutdownDelay = 15.0; while ( true ) { @@ -650,6 +647,22 @@ tcpiiu::~tcpiiu () } } + // wakeup user threads blocking for send backlog to be reduced + // and wait for them to stop using this IIU + this->flushBlockEvent.signal (); + while ( this->blockingForFlush ) { + epicsThreadSleep ( 0.1 ); + } + + this->sendDog.cancel (); + this->recvDog.cancel (); +} + +// +// tcpiiu::~tcpiiu () +// +tcpiiu::~tcpiiu () +{ if ( ! this->sockCloseCompleted ) { int status = socket_close ( this->sock ); if ( status ) { @@ -670,13 +683,6 @@ tcpiiu::~tcpiiu () this->pCAC()->releaseLargeBufferTCP ( this->pCurData ); } } - - // wakeup user threads blocking for send backlog to be reduced - // and wait for them to stop using this IIU - this->flushBlockEvent.signal (); - while ( this->blockingForFlush ) { - epicsThreadSleep ( 0.1 ); - } } void tcpiiu::destroy ()