optimized time fetch during flush

This commit is contained in:
Jeff Hill
2003-04-07 16:06:17 +00:00
parent 9519c2646a
commit 12efe1ec2b
8 changed files with 24 additions and 20 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -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") );
}

View File

@@ -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 (

View File

@@ -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 ()

View File

@@ -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;

View File

@@ -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 <unsigned> ( 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 ) {

View File

@@ -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;