tabs converted to spaces

This commit is contained in:
Jeff Hill
2000-10-11 19:29:45 +00:00
parent 48ca9b8a37
commit 6606dd6d31
2 changed files with 365 additions and 410 deletions

View File

@@ -66,9 +66,9 @@
// This explicitly instantiates the template class's member
// functions used by fdManager
//
// instantiated by "fdManager fileDescriptorManager;" statement below?
// (according to ms vis C++)
//
// instantiated by "fdManager fileDescriptorManager;" statement below?
// (according to ms vis C++)
//
template class resTable <fdReg, fdRegId>;
#endif
@@ -92,21 +92,21 @@ inline const unsigned fdRegId::maxIndexBitWidth ()
// fdManager::fdManager()
//
epicsShareFunc fdManager::fdManager (osiTimerQueue &timerQueueIn) :
fdTbl (1<<hashTableIndexBits),
fdTbl (1<<hashTableIndexBits),
timerQueue (timerQueueIn)
{
size_t i;
size_t i;
int status;
status = osiSockAttach ();
assert (status);
assert (status);
for ( i=0u; i < sizeof (this->fdSets) / sizeof ( this->fdSets[0u] ); i++ ) {
FD_ZERO ( &this->fdSets[i] );
}
this->maxFD = 0;
this->processInProg = 0u;
this->pCBReg = 0;
for ( i=0u; i < sizeof (this->fdSets) / sizeof ( this->fdSets[0u] ); i++ ) {
FD_ZERO ( &this->fdSets[i] );
}
this->maxFD = 0;
this->processInProg = 0u;
this->pCBReg = 0;
}
//
@@ -114,17 +114,17 @@ epicsShareFunc fdManager::fdManager (osiTimerQueue &timerQueueIn) :
//
epicsShareFunc fdManager::~fdManager()
{
fdReg *pReg;
fdReg *pReg;
while ( (pReg = this->regList.get()) ) {
pReg->state = fdReg::limbo;
pReg->destroy();
}
while ( (pReg = this->activeList.get()) ) {
pReg->state = fdReg::limbo;
pReg->destroy();
}
osiSockRelease();
while ( (pReg = this->regList.get()) ) {
pReg->state = fdReg::limbo;
pReg->destroy();
}
while ( (pReg = this->activeList.get()) ) {
pReg->state = fdReg::limbo;
pReg->destroy();
}
osiSockRelease();
}
//
@@ -132,135 +132,135 @@ epicsShareFunc fdManager::~fdManager()
//
epicsShareFunc void fdManager::process (double delay)
{
double minDelay;
fdReg *pReg;
struct timeval tv;
int status;
int ioPending = 0;
double minDelay;
fdReg *pReg;
struct timeval tv;
int status;
int ioPending = 0;
//
// no recursion
//
if (this->processInProg) {
return;
}
this->processInProg = 1;
//
// no recursion
//
if (this->processInProg) {
return;
}
this->processInProg = 1;
//
// One shot at expired timers prior to going into
// select. This allows zero delay timers to arm
// fd writes. We will never process the timer queue
// more than once here so that fd activity get serviced
// in a reasonable length of time.
//
minDelay = this->timerQueue.delayToFirstExpire();
if (minDelay<=0.0) {
this->timerQueue.process();
minDelay = this->timerQueue.delayToFirstExpire();
}
//
// One shot at expired timers prior to going into
// select. This allows zero delay timers to arm
// fd writes. We will never process the timer queue
// more than once here so that fd activity get serviced
// in a reasonable length of time.
//
minDelay = this->timerQueue.delayToFirstExpire();
if (minDelay<=0.0) {
this->timerQueue.process();
minDelay = this->timerQueue.delayToFirstExpire();
}
if (minDelay>=delay) {
minDelay = delay;
}
if (minDelay>=delay) {
minDelay = delay;
}
tsDLIterBD<fdReg> iter (this->regList.first());
while ( iter.valid () ) {
FD_SET(iter->getFD(), &this->fdSets[iter->getType()]);
ioPending = 1;
while ( iter.valid () ) {
FD_SET(iter->getFD(), &this->fdSets[iter->getType()]);
ioPending = 1;
++iter;
}
}
tv.tv_sec = static_cast<long> (minDelay);
tv.tv_usec = static_cast<long> ((minDelay-tv.tv_sec)*osiTime::uSecPerSec);
tv.tv_sec = static_cast<long> (minDelay);
tv.tv_usec = static_cast<long> ((minDelay-tv.tv_sec)*osiTime::uSecPerSec);
/*
* win32 requires this (others will
* run faster with this installed)
*/
if (!ioPending) {
/*
* recover from subtle differences between
* windows sockets and UNIX sockets implementation
* of select()
*/
if (minDelay>0.0) threadSleep(minDelay);
status = 0;
}
else {
status = select (this->maxFD, &this->fdSets[fdrRead],
&this->fdSets[fdrWrite], &this->fdSets[fdrException], &tv);
}
/*
* win32 requires this (others will
* run faster with this installed)
*/
if (!ioPending) {
/*
* recover from subtle differences between
* windows sockets and UNIX sockets implementation
* of select()
*/
if (minDelay>0.0) threadSleep(minDelay);
status = 0;
}
else {
status = select (this->maxFD, &this->fdSets[fdrRead],
&this->fdSets[fdrWrite], &this->fdSets[fdrException], &tv);
}
this->timerQueue.process();
if (status==0) {
this->processInProg = 0;
return;
}
else if (status<0) {
this->timerQueue.process();
if (status==0) {
this->processInProg = 0;
return;
}
else if (status<0) {
int errnoCpy = SOCKERRNO;
//
// print a message if its an unexpected error
//
if (errnoCpy != SOCK_EINTR) {
fprintf(stderr,
"fdManager: select failed because \"%s\"\n",
SOCKERRSTR(errnoCpy));
}
if (errnoCpy != SOCK_EINTR) {
fprintf(stderr,
"fdManager: select failed because \"%s\"\n",
SOCKERRSTR(errnoCpy));
}
this->processInProg = 0;
this->processInProg = 0;
return;
return;
}
//
// Look for activity
//
iter=this->regList.first();
while ( iter.valid () ) {
//
// Look for activity
//
iter=this->regList.first();
while ( iter.valid () ) {
tsDLIterBD<fdReg> tmp = iter;
tmp++;
if (FD_ISSET(iter->getFD(), &this->fdSets[iter->getType()])) {
FD_CLR(iter->getFD(), &this->fdSets[iter->getType()]);
this->regList.remove(*iter);
this->activeList.add(*iter);
iter->state = fdReg::active;
}
iter=tmp;
}
tmp++;
if (FD_ISSET(iter->getFD(), &this->fdSets[iter->getType()])) {
FD_CLR(iter->getFD(), &this->fdSets[iter->getType()]);
this->regList.remove(*iter);
this->activeList.add(*iter);
iter->state = fdReg::active;
}
iter=tmp;
}
//
// I am careful to prevent problems if they access the
// above list while in a "callBack()" routine
//
while ( (pReg = this->activeList.get()) ) {
pReg->state = fdReg::limbo;
//
// I am careful to prevent problems if they access the
// above list while in a "callBack()" routine
//
while ( (pReg = this->activeList.get()) ) {
pReg->state = fdReg::limbo;
//
// Tag current fdReg so that we
// can detect if it was deleted
// during the call back
//
this->pCBReg = pReg;
pReg->callBack();
if (this->pCBReg != NULL) {
//
// check only after we see that it is non-null so
// that we dont trigger bounds-checker dangling pointer
// error
//
assert (this->pCBReg==pReg);
this->pCBReg = 0;
if (pReg->onceOnly) {
pReg->destroy();
}
else {
this->regList.add(*pReg);
pReg->state = fdReg::pending;
}
}
}
this->processInProg = 0;
//
// Tag current fdReg so that we
// can detect if it was deleted
// during the call back
//
this->pCBReg = pReg;
pReg->callBack();
if (this->pCBReg != NULL) {
//
// check only after we see that it is non-null so
// that we dont trigger bounds-checker dangling pointer
// error
//
assert (this->pCBReg==pReg);
this->pCBReg = 0;
if (pReg->onceOnly) {
pReg->destroy();
}
else {
this->regList.add(*pReg);
pReg->state = fdReg::pending;
}
}
}
this->processInProg = 0;
}
//
@@ -269,7 +269,7 @@ epicsShareFunc void fdManager::process (double delay)
//
epicsShareFunc void fdReg::destroy()
{
delete this;
delete this;
}
//
@@ -277,7 +277,7 @@ epicsShareFunc void fdReg::destroy()
//
epicsShareFunc fdReg::~fdReg()
{
this->manager.removeReg(*this);
this->manager.removeReg(*this);
}
//
@@ -285,12 +285,12 @@ epicsShareFunc fdReg::~fdReg()
//
epicsShareFunc void fdReg::show(unsigned level) const
{
printf ("fdReg at %p\n", (void *) this);
if (level>1u) {
printf ("\tstate = %d, onceOnly = %d\n",
this->state, this->onceOnly);
}
this->fdRegId::show(level);
printf ("fdReg at %p\n", (void *) this);
if (level>1u) {
printf ("\tstate = %d, onceOnly = %d\n",
this->state, this->onceOnly);
}
this->fdRegId::show(level);
}
//
@@ -298,11 +298,11 @@ epicsShareFunc void fdReg::show(unsigned level) const
//
void fdRegId::show(unsigned level) const
{
printf ("fdRegId at %p\n", this);
if (level>1u) {
printf ("\tfd = %d, type = %d\n",
this->fd, this->type);
}
printf ("fdRegId at %p\n", this);
if (level>1u) {
printf ("\tfd = %d, type = %d\n",
this->fd, this->type);
}
}
//
@@ -311,11 +311,11 @@ void fdRegId::show(unsigned level) const
epicsShareFunc void fdManager::installReg (fdReg &reg)
{
this->maxFD = tsMax(this->maxFD, reg.getFD()+1);
this->regList.add (reg);
reg.state = fdReg::pending;
this->regList.add (reg);
reg.state = fdReg::pending;
int status = this->fdTbl.add (reg);
if (status!=0) {
if (status!=0) {
throwWithLocation ( fdInterestSubscriptionAlreadyExits () );
}
}
@@ -325,41 +325,41 @@ epicsShareFunc void fdManager::installReg (fdReg &reg)
//
void fdManager::removeReg (fdReg &regIn)
{
fdReg *pItemFound;
fdReg *pItemFound;
pItemFound = this->fdTbl.remove (regIn);
if (pItemFound!=&regIn) {
fprintf(stderr,
"fdManager::removeReg() bad fd registration object\n");
return;
}
pItemFound = this->fdTbl.remove (regIn);
if (pItemFound!=&regIn) {
fprintf(stderr,
"fdManager::removeReg() bad fd registration object\n");
return;
}
//
// signal fdManager that the fdReg was deleted
// during the call back
//
if (this->pCBReg == &regIn) {
this->pCBReg = 0;
}
switch (regIn.state) {
case fdReg::active:
//
// signal fdManager that the fdReg was deleted
// during the call back
//
if (this->pCBReg == &regIn) {
this->pCBReg = 0;
}
switch (regIn.state) {
case fdReg::active:
this->activeList.remove (regIn);
break;
case fdReg::pending:
break;
case fdReg::pending:
this->regList.remove (regIn);
break;
case fdReg::limbo:
break;
default:
//
// here if memory corrupted
//
assert(0);
}
regIn.state = fdReg::limbo;
break;
case fdReg::limbo:
break;
default:
//
// here if memory corrupted
//
assert(0);
}
regIn.state = fdReg::limbo;
FD_CLR(regIn.getFD(), &this->fdSets[regIn.getType()]);
FD_CLR(regIn.getFD(), &this->fdSets[regIn.getType()]);
}
//
@@ -367,26 +367,26 @@ void fdManager::removeReg (fdReg &regIn)
//
epicsShareFunc fdReg *fdManager::lookUpFD (const SOCKET fd, const fdRegType type)
{
if (fd<0) {
return NULL;
}
fdRegId id (fd,type);
return this->fdTbl.lookup(id);
if (fd<0) {
return NULL;
}
fdRegId id (fd,type);
return this->fdTbl.lookup(id);
}
//
// fdReg::fdReg()
//
fdReg::fdReg (const SOCKET fdIn, const fdRegType typIn,
const bool onceOnlyIn, fdManager &managerIn) :
fdRegId (fdIn,typIn), state (limbo),
onceOnly (onceOnlyIn), manager (managerIn)
const bool onceOnlyIn, fdManager &managerIn) :
fdRegId (fdIn,typIn), state (limbo),
onceOnly (onceOnlyIn), manager (managerIn)
{
if (!FD_IN_FDSET(fdIn)) {
fprintf (stderr, "%s: fd > FD_SETSIZE ignored\n",
__FILE__);
return;
}
this->manager.installReg (*this);
if (!FD_IN_FDSET(fdIn)) {
fprintf (stderr, "%s: fd > FD_SETSIZE ignored\n",
__FILE__);
return;
}
this->manager.installReg (*this);
}