From 12efe1ec2bec6cabd12129b06d33211ec5c140d1 Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Mon, 7 Apr 2003 16:06:17 +0000 Subject: [PATCH] optimized time fetch during flush --- src/ca/comBuf.cpp | 4 ++-- src/ca/comBuf.h | 7 ++++--- src/ca/tcpRecvWatchdog.cpp | 4 ++-- src/ca/tcpRecvWatchdog.h | 3 ++- src/ca/tcpSendWatchdog.cpp | 4 ++-- src/ca/tcpSendWatchdog.h | 2 +- src/ca/tcpiiu.cpp | 17 +++++++++-------- src/ca/virtualCircuit.h | 3 ++- 8 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/ca/comBuf.cpp b/src/ca/comBuf.cpp index fa22bcd68..6bf366524 100644 --- a/src/ca/comBuf.cpp +++ b/src/ca/comBuf.cpp @@ -29,13 +29,13 @@ #include "comBuf.h" #include "errlog.h" -bool comBuf::flushToWire ( wireSendAdapter & wire ) +bool comBuf::flushToWire ( wireSendAdapter & wire, const epicsTime & currentTime ) { unsigned index = this->nextReadIndex; unsigned finalIndex = this->commitIndex; while ( index < finalIndex ) { unsigned nBytes = wire.sendBytes ( - &this->buf[index], finalIndex - index ); + &this->buf[index], finalIndex - index, currentTime ); if ( nBytes == 0u ) { this->nextReadIndex = index; return false; diff --git a/src/ca/comBuf.h b/src/ca/comBuf.h index f697f58a6..70a45ed00 100644 --- a/src/ca/comBuf.h +++ b/src/ca/comBuf.h @@ -48,8 +48,9 @@ public: class wireSendAdapter { // X aCC 655 public: - virtual unsigned sendBytes ( const void *pBuf, - unsigned nBytesInBuf ) = 0; + virtual unsigned sendBytes ( const void * pBuf, + unsigned nBytesInBuf, + const class epicsTime & currentTime ) = 0; }; class wireRecvAdapter { // X aCC 655 @@ -93,7 +94,7 @@ public: unsigned copyOutBytes ( void *pBuf, unsigned nBytes ); bool copyOutAllBytes ( void *pBuf, unsigned nBytes ); unsigned removeBytes ( unsigned nBytes ); - bool flushToWire ( wireSendAdapter & ); + bool flushToWire ( wireSendAdapter &, const epicsTime & currentTime ); unsigned fillFromWire ( wireRecvAdapter & ); struct popStatus { bool success; diff --git a/src/ca/tcpRecvWatchdog.cpp b/src/ca/tcpRecvWatchdog.cpp index 525d95205..7f6c01104 100644 --- a/src/ca/tcpRecvWatchdog.cpp +++ b/src/ca/tcpRecvWatchdog.cpp @@ -116,14 +116,14 @@ void tcpRecvWatchdog::messageArrivalNotify ( const epicsTime & currentTime ) // The send watchdog will be responsible for detecting // dead connections in this case. // -void tcpRecvWatchdog::sendBacklogProgressNotify () +void tcpRecvWatchdog::sendBacklogProgressNotify ( const epicsTime & currentTime ) { // We dont set "beaconAnomaly" to be false here because, after we see a // beacon anomaly (which could be transiently detecting a reboot) we will // not trust the beacon as an indicator of a healthy server until we // receive at least one message from the server. this->responsePending = false; - this->timer.start ( *this, this->period ); + this->timer.start ( *this, currentTime + this->period ); debugPrintf ( ("saw heavy send backlog - reseting TCP recv watchdog\n") ); } diff --git a/src/ca/tcpRecvWatchdog.h b/src/ca/tcpRecvWatchdog.h index 6b3b0db78..e257c669b 100644 --- a/src/ca/tcpRecvWatchdog.h +++ b/src/ca/tcpRecvWatchdog.h @@ -37,7 +37,8 @@ public: double periodIn, epicsTimerQueue & ); virtual ~tcpRecvWatchdog (); void rescheduleRecvTimer (); - void sendBacklogProgressNotify (); + void sendBacklogProgressNotify ( + const epicsTime & currentTime ); void messageArrivalNotify ( const epicsTime & currentTime ); void beaconArrivalNotify ( diff --git a/src/ca/tcpSendWatchdog.cpp b/src/ca/tcpSendWatchdog.cpp index cc7bf5834..c5fb43a35 100644 --- a/src/ca/tcpSendWatchdog.cpp +++ b/src/ca/tcpSendWatchdog.cpp @@ -58,9 +58,9 @@ epicsTimerNotify::expireStatus tcpSendWatchdog::expire ( return noRestart; } -void tcpSendWatchdog::start () +void tcpSendWatchdog::start ( const epicsTime & currentTime ) { - this->timer.start ( *this, this->period ); + this->timer.start ( *this, currentTime + this->period ); } void tcpSendWatchdog::cancel () diff --git a/src/ca/tcpSendWatchdog.h b/src/ca/tcpSendWatchdog.h index 3af35422e..6e217fc4d 100644 --- a/src/ca/tcpSendWatchdog.h +++ b/src/ca/tcpSendWatchdog.h @@ -33,7 +33,7 @@ class tcpSendWatchdog : private epicsTimerNotify { public: tcpSendWatchdog ( cac &, tcpiiu &, double periodIn, epicsTimerQueue & queueIn ); virtual ~tcpSendWatchdog (); - void start (); + void start ( const epicsTime & ); void cancel (); private: const double period; diff --git a/src/ca/tcpiiu.cpp b/src/ca/tcpiiu.cpp index eb193d0bb..bacd4665d 100644 --- a/src/ca/tcpiiu.cpp +++ b/src/ca/tcpiiu.cpp @@ -144,18 +144,17 @@ void tcpSendThread::run () } unsigned tcpiiu::sendBytes ( const void *pBuf, - unsigned nBytesInBuf ) + unsigned nBytesInBuf, const epicsTime & currentTime ) { - int status; unsigned nBytes = 0u; assert ( nBytesInBuf <= INT_MAX ); - this->sendDog.start (); + this->sendDog.start ( currentTime ); while ( this->state == iiucs_connected || this->state == iiucs_clean_shutdown ) { - status = ::send ( this->sock, + int status = ::send ( this->sock, static_cast < const char * > (pBuf), (int) nBytesInBuf, 0 ); if ( status > 0 ) { nBytes = static_cast ( status ); @@ -543,7 +542,7 @@ void tcpiiu::connect () /* * attempt to connect to a CA server */ - this->sendDog.start (); + this->sendDog.start ( epicsTime::getCurrent() ); while ( this->state == iiucs_connecting ) { osiSockAddr tmp = this->address (); @@ -1151,9 +1150,9 @@ bool tcpiiu::flush () bool success = true; unsigned bytesToBeSent = 0u; + epicsTime current = epicsTime::getCurrent (); while ( true ) { comBuf * pBuf; - { epicsGuard < cacMutex > autoMutex ( this->cacRef.mutexRef() ); // set it here with this odd order because we must have @@ -1168,7 +1167,7 @@ bool tcpiiu::flush () bytesToBeSent = pBuf->occupiedBytes (); } - success = pBuf->flushToWire ( *this ); + success = pBuf->flushToWire ( *this, current ); pBuf->~comBuf (); this->comBufMemMgr.release ( pBuf ); @@ -1181,6 +1180,8 @@ bool tcpiiu::flush () break; } + current = epicsTime::getCurrent (); + // // we avoid calling this with the lock applied because // it restarts the recv wd timer, this might block @@ -1189,7 +1190,7 @@ bool tcpiiu::flush () // if ( this->unacknowledgedSendBytes > this->socketLibrarySendBufferSize ) { - this->recvDog.sendBacklogProgressNotify (); + this->recvDog.sendBacklogProgressNotify ( current ); } } if ( this->blockingForFlush ) { diff --git a/src/ca/virtualCircuit.h b/src/ca/virtualCircuit.h index db0b0ba86..773d5d613 100644 --- a/src/ca/virtualCircuit.h +++ b/src/ca/virtualCircuit.h @@ -177,7 +177,8 @@ private: bool processIncoming ( const epicsTime & currentTime, epicsGuard < callbackMutex > & ); - unsigned sendBytes ( const void *pBuf, unsigned nBytesInBuf ); + unsigned sendBytes ( const void *pBuf, + unsigned nBytesInBuf, const epicsTime & currentTime ); unsigned recvBytes ( void *pBuf, unsigned nBytesInBuf ); void connect (); const char * pHostName () const;