24 #define instantiateRecourceLib 46 pTimerQueue ( 0 ), maxFD ( 0 ), processInProg (
false ),
53 FD_ZERO ( &fdSetsPtr[
i] );
64 while ( (pReg = this->regList.
get()) ) {
65 pReg->state = fdReg::limbo;
68 while ( (pReg = this->activeList.
get()) ) {
69 pReg->state = fdReg::limbo;
72 delete this->pTimerQueue;
73 delete [] this->fdSetsPtr;
82 this->lazyInitTimerQueue ();
87 if (this->processInProg) {
90 this->processInProg =
true;
99 double minDelay = this->pTimerQueue->process(epicsTime::getCurrent());
101 if ( minDelay >= delay ) {
105 bool ioPending =
false;
107 while ( iter.
valid () ) {
108 FD_SET(iter->
getFD(), &this->fdSetsPtr[iter->
getType()]);
115 tv.tv_sec =
static_cast<time_t
> ( minDelay );
116 tv.tv_usec =
static_cast<long> ( (minDelay-tv.tv_sec) *
uSecPerSec );
118 fd_set * pReadSet = & this->fdSetsPtr[
fdrRead];
119 fd_set * pWriteSet = & this->fdSetsPtr[
fdrWrite];
121 int status =
select (this->maxFD, pReadSet, pWriteSet, pExceptSet, &tv);
123 this->pTimerQueue->process(epicsTime::getCurrent());
131 while ( iter.
valid () && status > 0 ) {
134 if (FD_ISSET(iter->
getFD(), &this->fdSetsPtr[iter->
getType()])) {
135 FD_CLR(iter->
getFD(), &this->fdSetsPtr[iter->
getType()]);
136 this->regList.
remove(*iter);
137 this->activeList.
add(*iter);
138 iter->state = fdReg::active;
149 while ( (pReg = this->activeList.
get()) ) {
150 pReg->state = fdReg::limbo;
159 if (this->pCBReg !=
NULL) {
165 assert (this->pCBReg==pReg);
167 if (pReg->onceOnly) {
171 this->regList.
add(*pReg);
172 pReg->state = fdReg::pending;
177 else if ( status < 0 ) {
183 FD_ZERO ( &fdSetsPtr[
i] );
192 sockErrBuf,
sizeof ( sockErrBuf ) );
194 "fdManager: select failed because \"%s\"\n",
206 this->pTimerQueue->process(epicsTime::getCurrent());
208 this->processInProg =
false;
226 this->manager.removeReg(*
this);
234 printf (
"fdReg at %p\n", (
void *)
this);
236 printf (
"\tstate = %d, onceOnly = %d\n",
237 this->state, this->onceOnly);
247 printf (
"fdRegId at %p\n",
248 static_cast <const void *> (
this ) );
250 printf (
"\tfd = %d, type = %d\n",
251 int(this->fd), this->
type );
258 void fdManager::installReg (
fdReg ®)
260 this->maxFD =
max ( this->maxFD, reg.
getFD()+1 );
265 this->regList.
push ( reg );
266 reg.state = fdReg::pending;
277 void fdManager::removeReg (
fdReg ®In)
281 pItemFound = this->fdTbl.
remove (regIn);
282 if (pItemFound!=®In) {
284 "fdManager::removeReg() bad fd registration object\n");
292 if (this->pCBReg == ®In) {
296 switch (regIn.state) {
298 this->activeList.
remove (regIn);
301 this->regList.
remove (regIn);
311 regIn.state = fdReg::limbo;
313 FD_CLR(regIn.
getFD(), &this->fdSetsPtr[regIn.
getType()]);
321 void fdManager::reschedule ()
325 double fdManager::quantum ()
327 return this->sleepQuantum;
339 return this->fdTbl.
lookup(
id);
346 const bool onceOnlyIn,
fdManager &managerIn) :
347 fdRegId (fdIn,typIn), state (limbo),
348 onceOnly (onceOnlyIn), manager (managerIn)
351 fprintf (
stderr,
"%s: fd > FD_SETSIZE ignored\n",
355 this->manager.installReg (*
this);
#define assert(exp)
Declare that a condition should be true.
fdRegType getType() const
An EPICS-specific replacement for ANSI C's assert.
fdManager fileDescriptorManager
LIBCOM_API double epicsStdCall epicsThreadSleepQuantum(void)
Query a value approximating the OS timer/scheduler resolution.
tsDLIterConst< T > firstIter() const
pvd::StructureConstPtr type
const unsigned uSecPerSec
T * lookup(const ID &idIn) const
void epicsSocketConvertErrnoToString(char *pBuf, unsigned bufSize)
LIBCOM_API class fdReg * lookUpFD(const SOCKET fd, const fdRegType type)
virtual void show(unsigned level) const
BSD and SRV5 Unix timestamp.
int select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
LIBCOM_API void process(double delay)
T * remove(const ID &idIn)
fdReg(const SOCKET fdIn, const fdRegType type, const bool onceOnly=false, fdManager &manager=fileDescriptorManager)
LIBCOM_API void epicsStdCall epicsThreadSleep(double seconds)
Block the calling thread for at least the specified time.
const unsigned mSecPerSec
C++ and C descriptions for a thread.
virtual LIBCOM_API ~fdManager()
#define throwWithLocation(parm)
virtual void show(unsigned level) const