This is Unofficial EPICS BASE Doxygen Site
fdManager Class Reference

#include "fdManager.h"

+ Inheritance diagram for fdManager:
+ Collaboration diagram for fdManager:

Classes

class  fdInterestSubscriptionAlreadyExits
 

Public Member Functions

LIBCOM_API fdManager ()
 
virtual LIBCOM_API ~fdManager ()
 
LIBCOM_API void process (double delay)
 
LIBCOM_API class fdReglookUpFD (const SOCKET fd, const fdRegType type)
 
epicsTimer & createTimer ()
 

Friends

class fdReg
 

Detailed Description

Definition at line 73 of file fdManager.h.

Constructor & Destructor Documentation

LIBCOM_API fdManager::fdManager ( )

Definition at line 43 of file fdManager.cpp.

43  :
44  sleepQuantum ( epicsThreadSleepQuantum () ),
45  fdSetsPtr ( new fd_set [fdrNEnums] ),
46  pTimerQueue ( 0 ), maxFD ( 0 ), processInProg ( false ),
47  pCBReg ( 0 )
48 {
49  int status = osiSockAttach ();
50  assert (status);
51 
52  for ( size_t i = 0u; i < fdrNEnums; i++ ) {
53  FD_ZERO ( &fdSetsPtr[i] );
54  }
55 }
#define assert(exp)
Declare that a condition should be true.
Definition: epicsAssert.h:70
pvd::Status status
int i
Definition: scan.c:967
LIBCOM_API double epicsStdCall epicsThreadSleepQuantum(void)
Query a value approximating the OS timer/scheduler resolution.
Definition: osdThread.c:981
int osiSockAttach()
Definition: osdSock.c:54
LIBCOM_API fdManager::~fdManager ( )
virtual

Definition at line 60 of file fdManager.cpp.

61 {
62  fdReg *pReg;
63 
64  while ( (pReg = this->regList.get()) ) {
65  pReg->state = fdReg::limbo;
66  pReg->destroy();
67  }
68  while ( (pReg = this->activeList.get()) ) {
69  pReg->state = fdReg::limbo;
70  pReg->destroy();
71  }
72  delete this->pTimerQueue;
73  delete [] this->fdSetsPtr;
75 }
virtual void destroy()
Definition: fdManager.cpp:216
void osiSockRelease()
Definition: osdSock.c:62
T * get()
Definition: tsDLList.h:261

Member Function Documentation

epicsTimer & fdManager::createTimer ( )
inline

Definition at line 197 of file fdManager.h.

198 {
199  this->lazyInitTimerQueue ();
200  return this->pTimerQueue->createTimer ();
201 }
LIBCOM_API fdReg * fdManager::lookUpFD ( const SOCKET  fd,
const fdRegType  type 
)

Definition at line 333 of file fdManager.cpp.

334 {
335  if (fd<0) {
336  return NULL;
337  }
338  fdRegId id (fd,type);
339  return this->fdTbl.lookup(id);
340 }
pvd::StructureConstPtr type
#define NULL
Definition: catime.c:38
T * lookup(const ID &idIn) const
Definition: resourceLib.h:342
LIBCOM_API void fdManager::process ( double  delay)

Definition at line 80 of file fdManager.cpp.

81 {
82  this->lazyInitTimerQueue ();
83 
84  //
85  // no recursion
86  //
87  if (this->processInProg) {
88  return;
89  }
90  this->processInProg = true;
91 
92  //
93  // One shot at expired timers prior to going into
94  // select. This allows zero delay timers to arm
95  // fd writes. We will never process the timer queue
96  // more than once here so that fd activity get serviced
97  // in a reasonable length of time.
98  //
99  double minDelay = this->pTimerQueue->process(epicsTime::getCurrent());
100 
101  if ( minDelay >= delay ) {
102  minDelay = delay;
103  }
104 
105  bool ioPending = false;
106  tsDLIter < fdReg > iter = this->regList.firstIter ();
107  while ( iter.valid () ) {
108  FD_SET(iter->getFD(), &this->fdSetsPtr[iter->getType()]);
109  ioPending = true;
110  ++iter;
111  }
112 
113  if ( ioPending ) {
114  struct timeval tv;
115  tv.tv_sec = static_cast<time_t> ( minDelay );
116  tv.tv_usec = static_cast<long> ( (minDelay-tv.tv_sec) * uSecPerSec );
117 
118  fd_set * pReadSet = & this->fdSetsPtr[fdrRead];
119  fd_set * pWriteSet = & this->fdSetsPtr[fdrWrite];
120  fd_set * pExceptSet = & this->fdSetsPtr[fdrException];
121  int status = select (this->maxFD, pReadSet, pWriteSet, pExceptSet, &tv);
122 
123  this->pTimerQueue->process(epicsTime::getCurrent());
124 
125  if ( status > 0 ) {
126 
127  //
128  // Look for activity
129  //
130  iter=this->regList.firstIter ();
131  while ( iter.valid () && status > 0 ) {
132  tsDLIter < fdReg > tmp = iter;
133  tmp++;
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;
139  status--;
140  }
141  iter = tmp;
142  }
143 
144  //
145  // I am careful to prevent problems if they access the
146  // above list while in a "callBack()" routine
147  //
148  fdReg * pReg;
149  while ( (pReg = this->activeList.get()) ) {
150  pReg->state = fdReg::limbo;
151 
152  //
153  // Tag current fdReg so that we
154  // can detect if it was deleted
155  // during the call back
156  //
157  this->pCBReg = pReg;
158  pReg->callBack();
159  if (this->pCBReg != NULL) {
160  //
161  // check only after we see that it is non-null so
162  // that we dont trigger bounds-checker dangling pointer
163  // error
164  //
165  assert (this->pCBReg==pReg);
166  this->pCBReg = 0;
167  if (pReg->onceOnly) {
168  pReg->destroy();
169  }
170  else {
171  this->regList.add(*pReg);
172  pReg->state = fdReg::pending;
173  }
174  }
175  }
176  }
177  else if ( status < 0 ) {
178  int errnoCpy = SOCKERRNO;
179 
180  // dont depend on flags being properly set if
181  // an error is retuned from select
182  for ( size_t i = 0u; i < fdrNEnums; i++ ) {
183  FD_ZERO ( &fdSetsPtr[i] );
184  }
185 
186  //
187  // print a message if its an unexpected error
188  //
189  if ( errnoCpy != SOCK_EINTR ) {
190  char sockErrBuf[64];
192  sockErrBuf, sizeof ( sockErrBuf ) );
193  fprintf ( stderr,
194  "fdManager: select failed because \"%s\"\n",
195  sockErrBuf );
196  }
197  }
198  }
199  else {
200  /*
201  * recover from subtle differences between
202  * windows sockets and UNIX sockets implementation
203  * of select()
204  */
205  epicsThreadSleep(minDelay);
206  this->pTimerQueue->process(epicsTime::getCurrent());
207  }
208  this->processInProg = false;
209  return;
210 }
virtual void destroy()
Definition: fdManager.cpp:216
#define assert(exp)
Declare that a condition should be true.
Definition: epicsAssert.h:70
void add(T &item)
Definition: tsDLList.h:313
fdRegType getType() const
Definition: fdManager.h:48
pvd::Status status
int i
Definition: scan.c:967
tsDLIterConst< T > firstIter() const
Definition: tsDLList.h:459
#define NULL
Definition: catime.c:38
const unsigned uSecPerSec
Definition: fdManager.cpp:35
bool valid() const
Definition: tsDLList.h:607
void epicsSocketConvertErrnoToString(char *pBuf, unsigned bufSize)
SOCKET getFD() const
Definition: fdManager.h:43
BSD and SRV5 Unix timestamp.
Definition: epicsTime.h:52
int select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
#define SOCKERRNO
Definition: osdSock.h:33
T * get()
Definition: tsDLList.h:261
#define SOCK_EINTR
Definition: osdSock.h:64
LIBCOM_API void epicsStdCall epicsThreadSleep(double seconds)
Block the calling thread for at least the specified time.
Definition: osdThread.c:790
void remove(T &item)
Definition: tsDLList.h:219
#define stderr
Definition: epicsStdio.h:32

Friends And Related Function Documentation

friend class fdReg
friend

Definition at line 110 of file fdManager.h.


The documentation for this class was generated from the following files: