From 452d3d68cac2f68e651443386299fec5bf54df5c Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Sat, 2 Nov 1996 02:04:42 +0000 Subject: [PATCH] fixed several subtle bugs --- src/libCom/fdManager.cc | 64 +++++++++++++++++++--------------- src/libCom/fdManager.h | 41 ++++++++++------------ src/libCom/fdmgr/fdManager.cpp | 64 +++++++++++++++++++--------------- src/libCom/fdmgr/fdManager.h | 41 ++++++++++------------ 4 files changed, 108 insertions(+), 102 deletions(-) diff --git a/src/libCom/fdManager.cc b/src/libCom/fdManager.cc index f089cde2e..4b8168b0f 100644 --- a/src/libCom/fdManager.cc +++ b/src/libCom/fdManager.cc @@ -4,6 +4,9 @@ // // // $Log$ +// Revision 1.2 1996/09/04 21:50:16 jhill +// added hashed fd to fdi convert +// // Revision 1.1 1996/08/13 22:48:23 jhill // dfMgr =>fdManager // @@ -12,7 +15,7 @@ // // // NOTES: -// 1) This isnt intended for a multi-threading environment +// 1) This library is not thread safe // // @@ -23,17 +26,23 @@ #include #include -#if __GNUC__ - extern "C" { -# include - int select (int, fd_set *, fd_set *, - fd_set *, struct timeval *); - int bzero (char *b, int length); - } //extern "C" -#endif // __GNUC__ +// Both the functions in osiTimer and fdManager are +// implemented in this DLL -> define epicsExportSharesSymbols +#define epicsExportSharedSymbols +#include "osiTimer.h" +#include "fdManager.h" -#include -#include +#if !defined(__SUNPRO_CC) + // + // From Stroustrups's "The C++ Programming Language" + // Appendix A: r.14.9 + // + // This explicitly instantiates the template class's member + // functions into "fdManager.o" + // +# include + template class resTable ; +#endif fdManager fileDescriptorManager; @@ -85,7 +94,7 @@ fdManager::~fdManager() // void fdManager::process (const osiTime &delay) { - tsDLIter regIter(this->regList); + tsDLFwdIter regIter(this->regList); osiTime minDelay; osiTime zeroDelay; fdReg *pReg; @@ -100,27 +109,26 @@ void fdManager::process (const osiTime &delay) } this->processInProg = 1; - while ( (pReg=regIter()) ) { - FD_SET(pReg->getFD(), &this->fdSets[pReg->getType()]); - } - // - // dont bother calling select if the delay to - // the first timer expire is zero + // 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. // - while (1) { + minDelay = staticTimerQueue.delayToFirstExpire(); + if (zeroDelay>=minDelay) { + staticTimerQueue.process(); minDelay = staticTimerQueue.delayToFirstExpire(); - if (zeroDelay>=minDelay) { - staticTimerQueue.process(); - } - else { - break; - } - } + } if (minDelay>=delay) { minDelay = delay; } + + while ( (pReg=regIter()) ) { + FD_SET(pReg->getFD(), &this->fdSets[pReg->getType()]); + } minDelay.getTV (tv.tv_sec, tv.tv_usec); status = select (this->maxFD, &this->fdSets[fdrRead], &this->fdSets[fdrWrite], &this->fdSets[fdrExcp], &tv); @@ -208,7 +216,7 @@ fdReg::~fdReg() // // fdReg::show() // -void fdReg::show(unsigned level) +void fdReg::show(unsigned level) const { printf ("fdReg at %x\n", (unsigned) this); if (level>1u) { @@ -221,7 +229,7 @@ void fdReg::show(unsigned level) // // fdRegId::show() // -void fdRegId::show(unsigned level) +void fdRegId::show(unsigned level) const { printf ("fdRegId at %x\n", (unsigned) this); if (level>1u) { diff --git a/src/libCom/fdManager.h b/src/libCom/fdManager.h index 3e41a6383..b8d8c4cc8 100644 --- a/src/libCom/fdManager.h +++ b/src/libCom/fdManager.h @@ -32,6 +32,9 @@ * * History * $Log$ + * Revision 1.2 1996/09/04 21:50:16 jhill + * added hashed fd to fdi convert + * * Revision 1.1 1996/08/13 22:48:21 jhill * dfMgr =>fdManager * @@ -41,21 +44,13 @@ #ifndef fdManagerH_included #define fdManagerH_included -#include -#include -#include - -#ifdef WIN32 -#include -#else -extern "C" { -# include -# include -} // extern "C" -#endif - #include +#include "tsDLList.h" +#include "resourceLib.h" +#include "osiTime.h" +#include "osiSock.h" + enum fdRegType {fdrRead, fdrWrite, fdrExcp, fdRegTypeNElem}; enum fdRegState {fdrActive, fdrPending, fdrLimbo}; @@ -100,7 +95,7 @@ public: return hashid; } - virtual void show(unsigned level); + virtual void show(unsigned level) const; private: const int fd; const fdRegType type; @@ -110,15 +105,15 @@ private: // fdReg // file descriptor registration // -class fdReg : public tsDLNode, public fdRegId, +class epicsShareClass fdReg : public tsDLNode, public fdRegId, public tsSLNode { friend class fdManager; public: - fdReg (const int fdIn, const fdRegType typ, + inline fdReg (const int fdIn, const fdRegType typ, const unsigned onceOnly=0); virtual ~fdReg (); - virtual void show(unsigned level); + virtual void show(unsigned level) const; private: // @@ -145,7 +140,7 @@ private: unsigned char onceOnly; }; -class fdManager { +class epicsShareClass fdManager { friend class fdReg; public: fdManager(); @@ -155,7 +150,7 @@ public: // // returns NULL if the fd is unknown // - fdReg *lookUpFD(const int fd, const fdRegType type); + inline fdReg *lookUpFD(const int fd, const fdRegType type); private: tsDLList regList; tsDLList activeList; @@ -168,12 +163,12 @@ private: // fdReg *pCBReg; - void installReg (fdReg ®); - void removeReg (fdReg ®); + inline void installReg (fdReg ®); + inline void removeReg (fdReg ®); resTable fdTbl; }; -extern fdManager fileDescriptorManager; +epicsShareExtern fdManager fileDescriptorManager; // // lookUpFD() @@ -259,7 +254,7 @@ inline fdReg::fdReg (const int fdIn, const fdRegType typIn, fdRegId(fdIn,typIn), state(fdrLimbo), onceOnly(onceOnlyIn) { assert (fdIn>=0); - if (fdIn>FD_SETSIZE) { + if (!FD_IN_FDSET(fdIn)) { fprintf (stderr, "%s: fd > FD_SETSIZE ignored\n", __FILE__); return; diff --git a/src/libCom/fdmgr/fdManager.cpp b/src/libCom/fdmgr/fdManager.cpp index f089cde2e..4b8168b0f 100644 --- a/src/libCom/fdmgr/fdManager.cpp +++ b/src/libCom/fdmgr/fdManager.cpp @@ -4,6 +4,9 @@ // // // $Log$ +// Revision 1.2 1996/09/04 21:50:16 jhill +// added hashed fd to fdi convert +// // Revision 1.1 1996/08/13 22:48:23 jhill // dfMgr =>fdManager // @@ -12,7 +15,7 @@ // // // NOTES: -// 1) This isnt intended for a multi-threading environment +// 1) This library is not thread safe // // @@ -23,17 +26,23 @@ #include #include -#if __GNUC__ - extern "C" { -# include - int select (int, fd_set *, fd_set *, - fd_set *, struct timeval *); - int bzero (char *b, int length); - } //extern "C" -#endif // __GNUC__ +// Both the functions in osiTimer and fdManager are +// implemented in this DLL -> define epicsExportSharesSymbols +#define epicsExportSharedSymbols +#include "osiTimer.h" +#include "fdManager.h" -#include -#include +#if !defined(__SUNPRO_CC) + // + // From Stroustrups's "The C++ Programming Language" + // Appendix A: r.14.9 + // + // This explicitly instantiates the template class's member + // functions into "fdManager.o" + // +# include + template class resTable ; +#endif fdManager fileDescriptorManager; @@ -85,7 +94,7 @@ fdManager::~fdManager() // void fdManager::process (const osiTime &delay) { - tsDLIter regIter(this->regList); + tsDLFwdIter regIter(this->regList); osiTime minDelay; osiTime zeroDelay; fdReg *pReg; @@ -100,27 +109,26 @@ void fdManager::process (const osiTime &delay) } this->processInProg = 1; - while ( (pReg=regIter()) ) { - FD_SET(pReg->getFD(), &this->fdSets[pReg->getType()]); - } - // - // dont bother calling select if the delay to - // the first timer expire is zero + // 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. // - while (1) { + minDelay = staticTimerQueue.delayToFirstExpire(); + if (zeroDelay>=minDelay) { + staticTimerQueue.process(); minDelay = staticTimerQueue.delayToFirstExpire(); - if (zeroDelay>=minDelay) { - staticTimerQueue.process(); - } - else { - break; - } - } + } if (minDelay>=delay) { minDelay = delay; } + + while ( (pReg=regIter()) ) { + FD_SET(pReg->getFD(), &this->fdSets[pReg->getType()]); + } minDelay.getTV (tv.tv_sec, tv.tv_usec); status = select (this->maxFD, &this->fdSets[fdrRead], &this->fdSets[fdrWrite], &this->fdSets[fdrExcp], &tv); @@ -208,7 +216,7 @@ fdReg::~fdReg() // // fdReg::show() // -void fdReg::show(unsigned level) +void fdReg::show(unsigned level) const { printf ("fdReg at %x\n", (unsigned) this); if (level>1u) { @@ -221,7 +229,7 @@ void fdReg::show(unsigned level) // // fdRegId::show() // -void fdRegId::show(unsigned level) +void fdRegId::show(unsigned level) const { printf ("fdRegId at %x\n", (unsigned) this); if (level>1u) { diff --git a/src/libCom/fdmgr/fdManager.h b/src/libCom/fdmgr/fdManager.h index 3e41a6383..b8d8c4cc8 100644 --- a/src/libCom/fdmgr/fdManager.h +++ b/src/libCom/fdmgr/fdManager.h @@ -32,6 +32,9 @@ * * History * $Log$ + * Revision 1.2 1996/09/04 21:50:16 jhill + * added hashed fd to fdi convert + * * Revision 1.1 1996/08/13 22:48:21 jhill * dfMgr =>fdManager * @@ -41,21 +44,13 @@ #ifndef fdManagerH_included #define fdManagerH_included -#include -#include -#include - -#ifdef WIN32 -#include -#else -extern "C" { -# include -# include -} // extern "C" -#endif - #include +#include "tsDLList.h" +#include "resourceLib.h" +#include "osiTime.h" +#include "osiSock.h" + enum fdRegType {fdrRead, fdrWrite, fdrExcp, fdRegTypeNElem}; enum fdRegState {fdrActive, fdrPending, fdrLimbo}; @@ -100,7 +95,7 @@ public: return hashid; } - virtual void show(unsigned level); + virtual void show(unsigned level) const; private: const int fd; const fdRegType type; @@ -110,15 +105,15 @@ private: // fdReg // file descriptor registration // -class fdReg : public tsDLNode, public fdRegId, +class epicsShareClass fdReg : public tsDLNode, public fdRegId, public tsSLNode { friend class fdManager; public: - fdReg (const int fdIn, const fdRegType typ, + inline fdReg (const int fdIn, const fdRegType typ, const unsigned onceOnly=0); virtual ~fdReg (); - virtual void show(unsigned level); + virtual void show(unsigned level) const; private: // @@ -145,7 +140,7 @@ private: unsigned char onceOnly; }; -class fdManager { +class epicsShareClass fdManager { friend class fdReg; public: fdManager(); @@ -155,7 +150,7 @@ public: // // returns NULL if the fd is unknown // - fdReg *lookUpFD(const int fd, const fdRegType type); + inline fdReg *lookUpFD(const int fd, const fdRegType type); private: tsDLList regList; tsDLList activeList; @@ -168,12 +163,12 @@ private: // fdReg *pCBReg; - void installReg (fdReg ®); - void removeReg (fdReg ®); + inline void installReg (fdReg ®); + inline void removeReg (fdReg ®); resTable fdTbl; }; -extern fdManager fileDescriptorManager; +epicsShareExtern fdManager fileDescriptorManager; // // lookUpFD() @@ -259,7 +254,7 @@ inline fdReg::fdReg (const int fdIn, const fdRegType typIn, fdRegId(fdIn,typIn), state(fdrLimbo), onceOnly(onceOnlyIn) { assert (fdIn>=0); - if (fdIn>FD_SETSIZE) { + if (!FD_IN_FDSET(fdIn)) { fprintf (stderr, "%s: fd > FD_SETSIZE ignored\n", __FILE__); return;