From cc21e955bfca3a0f0bea6913a9862ed41c718cc0 Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Thu, 7 Sep 2000 19:32:48 +0000 Subject: [PATCH] changed abotive shutdown --- src/ca/tcpiiu.cpp | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/src/ca/tcpiiu.cpp b/src/ca/tcpiiu.cpp index b6617acd0..2cab0c40a 100644 --- a/src/ca/tcpiiu.cpp +++ b/src/ca/tcpiiu.cpp @@ -238,7 +238,7 @@ unsigned tcpiiu::sendBytes ( const void *pBuf, unsigned nBytesInBuf ) if ( localError == SOCK_EINTR ) { continue; } - + if ( localError != SOCK_EPIPE && localError != SOCK_ECONNRESET && localError != SOCK_ETIMEDOUT && localError != SOCK_ECONNABORTED ) { ca_printf ("CAC: unexpected TCP send error: %s\n", SOCKERRSTR (localError) ); @@ -286,6 +286,10 @@ unsigned tcpiiu::recvBytes ( void *pBuf, unsigned nBytesInBuf ) return 0u; } + if ( localErrno == SOCK_ECONNRESET ) { + return 0u; + } + { char name[64]; this->hostName ( name, sizeof (name) ); @@ -535,6 +539,14 @@ void tcpiiu::cleanShutdown () if ( status ) { errlogPrintf ("CAC TCP socket shutdown error was %s\n", SOCKERRSTR (SOCKERRNO) ); + status = socket_close ( this->sock ); + if ( status ) { + errlogPrintf ("CAC TCP socket close error was %s\n", + SOCKERRSTR (SOCKERRNO) ); + } + else { + this->sock = INVALID_SOCKET; + } } semBinaryGive ( this->sendThreadFlushSignal ); semBinaryGive ( this->recvThreadRingBufferSpaceAvailableSignal ); @@ -551,11 +563,28 @@ void tcpiiu::forcedShutdown () this->lock (); if ( this->state != iiu_disconnected ) { this->state = iiu_disconnected; - int status = socket_close ( this->sock ); + + struct linger tmpLinger; + tmpLinger.l_onoff = true; + tmpLinger.l_linger = 0u; + + // force abortive clousure + int status = setsockopt ( this->sock, SOL_SOCKET, SO_LINGER, + reinterpret_cast ( &tmpLinger ), sizeof (tmpLinger) ); + if ( status != 0 ) { + errlogPrintf ( "CAC TCP socket linger set error was %s\n", + SOCKERRSTR (SOCKERRNO) ); + } + + status = socket_close ( this->sock ); if ( status ) { errlogPrintf ("CAC TCP socket close error was %s\n", SOCKERRSTR (SOCKERRNO) ); } + else { + this->sock = INVALID_SOCKET; + } + semBinaryGive ( this->sendThreadFlushSignal ); semBinaryGive ( this->recvThreadRingBufferSpaceAvailableSignal ); this->clientCtx ().signalRecvActivity (); @@ -602,6 +631,14 @@ tcpiiu::~tcpiiu () if ( this->pCurData ) { free ( this->pCurData ); } + + if ( this->sock != INVALID_SOCKET ) { + int status = socket_close ( this->sock ); + if ( status ) { + errlogPrintf ("CAC TCP socket close error was %s\n", + SOCKERRSTR ( SOCKERRNO ) ); + } + } } void tcpiiu::suicide () @@ -637,7 +674,7 @@ void tcpiiu::show ( unsigned level ) const this->netiiu::show ( level - 1u ); } if ( level > 2u ) { - printf ( "\tcurrent data cache pointer = %p current data cache size = %u\n", + printf ( "\tcurrent data cache pointer = %p current data cache size = %lu\n", this->pCurData, this->curDataMax ); printf ( "\tcontiguous receive message count=%u, busy detect bool=%u, flow control bool=%u\n", this->contigRecvMsgCount, this->busyStateDetected, this->flowControlActive );