o no need to allocate or initialize one more fd_set than is used

(not a bug but messy)
o added optimization where we only check as many registered fd's
on the list as select tells us are active in its status
o added code to clear all of the  fd_set if select returns an error
(in practice this would not cause a bug other than some extra activity
that would immediately self terminate when it clear the flag in the fd_set,
and also we dont see the error message printed when select returns an error)
This commit is contained in:
Jeff Hill
2009-07-30 23:21:19 +00:00
parent 001b947702
commit 72e1dba496

View File

@@ -21,7 +21,6 @@
// 1) This library is not thread safe
//
#undef FD_SETSIZE
#define FD_SETSIZE 4096
//
@@ -51,15 +50,15 @@ const unsigned uSecPerSec = 1000u * mSecPerSec;
//
epicsShareFunc fdManager::fdManager () :
sleepQuantum ( epicsThreadSleepQuantum () ),
fdSetsPtr ( new fd_set [fdrNEnums+1] ),
fdSetsPtr ( new fd_set [fdrNEnums] ),
pTimerQueue ( 0 ), maxFD ( 0 ), processInProg ( false ),
pCBReg ( 0 )
{
int status = osiSockAttach ();
assert (status);
for ( size_t i = 0u; i <= fdrNEnums; i++ ) {
FD_ZERO ( &fdSetsPtr[i] ); // X aCC 392
for ( size_t i = 0u; i < fdrNEnums; i++ ) {
FD_ZERO ( &fdSetsPtr[i] );
}
}
@@ -124,8 +123,10 @@ epicsShareFunc void fdManager::process (double delay)
tv.tv_sec = static_cast<long> ( minDelay );
tv.tv_usec = static_cast<long> ( (minDelay-tv.tv_sec) * uSecPerSec );
int status = select (this->maxFD, &this->fdSetsPtr[fdrRead],
&this->fdSetsPtr[fdrWrite], &this->fdSetsPtr[fdrException], &tv);
fd_set * pReadSet = & this->fdSetsPtr[fdrRead];
fd_set * pWriteSet = & this->fdSetsPtr[fdrWrite];
fd_set * pExceptSet = & this->fdSetsPtr[fdrException];
int status = select (this->maxFD, pReadSet, pWriteSet, pExceptSet, &tv);
this->pTimerQueue->process(epicsTime::getCurrent());
@@ -135,16 +136,17 @@ epicsShareFunc void fdManager::process (double delay)
// Look for activity
//
iter=this->regList.firstIter ();
while ( iter.valid () ) {
tsDLIter<fdReg> tmp = iter;
while ( iter.valid () && status > 0 ) {
tsDLIter < fdReg > tmp = iter;
tmp++;
if (FD_ISSET(iter->getFD(), &this->fdSetsPtr[iter->getType()])) {
FD_CLR(iter->getFD(), &this->fdSetsPtr[iter->getType()]);
this->regList.remove(*iter);
this->activeList.add(*iter);
iter->state = fdReg::active;
status--;
}
iter=tmp;
iter = tmp;
}
//
@@ -182,6 +184,12 @@ epicsShareFunc void fdManager::process (double delay)
}
else if ( status < 0 ) {
int errnoCpy = SOCKERRNO;
// dont depend on flags being properly set if
// an error is retuned from select
for ( size_t i = 0u; i < fdrNEnums; i++ ) {
FD_ZERO ( &fdSetsPtr[i] );
}
//
// print a message if its an unexpected error