summaryrefslogtreecommitdiff
path: root/comm
diff options
context:
space:
mode:
authorchatty1993-07-26 07:52:54 +0000
committerchatty1993-07-26 07:52:54 +0000
commit4068e7bb6e42d94f2f2b14c1667e77b9d19ce9b6 (patch)
treed25f9b5a20d199e1a2a84471f5bc5fd0f0d41b67 /comm
parent97d910ab97da81e64c036e2096e82dbfa662a122 (diff)
downloadivy-league-4068e7bb6e42d94f2f2b14c1667e77b9d19ce9b6.zip
ivy-league-4068e7bb6e42d94f2f2b14c1667e77b9d19ce9b6.tar.gz
ivy-league-4068e7bb6e42d94f2f2b14c1667e77b9d19ce9b6.tar.bz2
ivy-league-4068e7bb6e42d94f2f2b14c1667e77b9d19ce9b6.tar.xz
Added functions for UchSignalHandlers
Diffstat (limited to 'comm')
-rw-r--r--comm/Multiplexer.cc36
-rw-r--r--comm/Multiplexer.h6
2 files changed, 41 insertions, 1 deletions
diff --git a/comm/Multiplexer.cc b/comm/Multiplexer.cc
index 3ac88ff..a763c6d 100644
--- a/comm/Multiplexer.cc
+++ b/comm/Multiplexer.cc
@@ -14,7 +14,9 @@
#include "Multiplexer.h"
#include "TimeOut.h"
+#include "Signal.h"
+#include <signal.h> // for NSIG
#include <sys/errno.h>
#include <sys/time.h>
#include <sys/socket.h>
@@ -75,11 +77,16 @@ UchMultiplexer :: UchMultiplexer ()
WriteCount (0),
SelectCount (0),
Looping (FALSE),
- TimeOut (-1)
+ SigFired (FALSE),
+ TimeOut (-1),
+ Handlers (new UchBaseSignalHandler* [NSIG]),
+ NbSignals (new int [NSIG])
{
FD_ZERO (&ReadMask);
FD_ZERO (&WriteMask);
FD_ZERO (&SelectMask);
+ memset (Handlers, 0, NSIG * sizeof (UchBaseSignalHandler*));
+ memset (NbSignals, 0, NSIG * sizeof (int));
}
/*?nodoc?*/
@@ -89,6 +96,8 @@ UchMultiplexer :: ~UchMultiplexer ()
delete [NFILE] Channels;
#else
delete [] Channels;
+ delete [] NbSignals;
+ delete [] Handlers;
#endif
Channels = 0;
}
@@ -263,6 +272,7 @@ UchMultiplexer :: SetModeNotify (UchChannel*, IOMODE)
// nothing
}
+////// should add signal handling
/*?nextdoc?*/
int
UchMultiplexer :: Scan (bool nointr, bool poll)
@@ -368,8 +378,22 @@ UchMultiplexer :: LoopScan (bool nointr)
Looping = TRUE;
for (fd0 = 0; Looping; fd0 < NFILE ? fd0++ : (fd0 = 0)) {
+ /* First, handle signals */
+ if (SigFired) {
+ CcuSignalBlocker b (AllSigs);
+ int c;
+ for (int i = 0; i < NSIG; ++i)
+ if (c = NbSignals [i]) {
+ Handlers [i]->DeferredHandle (c);
+ NbSignals [i] = 0;
+ Handlers [i] = 0;
+ }
+ }
+
+ /* Then, timers */
CcuCoreTimer::Fire (&Timers);
+ /* Then, I/Os */
if (ReadCount == 0 && WriteCount == 0 && SelectCount == 0)
return 0;
@@ -462,3 +486,13 @@ UchMultiplexer :: LoopEnd ()
#endif /* DOC */
+void
+UchMultiplexer :: RegisterSignal (UchBaseSignalHandler& h)
+{
+ SigFired = TRUE;
+ int sig = h.GetSignal () - 1;
+ /* We have to work with arrays, because we are in a signal
+ handler, and we cannot use lists */
+ Handlers [sig] = &h;
+ NbSignals [sig]++;
+}
diff --git a/comm/Multiplexer.h b/comm/Multiplexer.h
index 0c30bfd..7024463 100644
--- a/comm/Multiplexer.h
+++ b/comm/Multiplexer.h
@@ -32,6 +32,7 @@ extern char* StrReprBuf;
//
class UchMultiplexer : public CcuSmartData {
friend class UchBaseTimeOut;
+friend class UchBaseSignalHandler;
protected:
pUchChannel* Channels;
@@ -44,6 +45,9 @@ protected:
short SelectCount;
bool Looping;
Millisecond TimeOut;
+ bool SigFired;
+ UchBaseSignalHandler** Handlers;
+ int* NbSignals;
int fd0; // used by HandleSelect and LoopScan
void SetMasks (int, IOMODE);
@@ -51,6 +55,8 @@ inline CcuTimerSet* GetTimerSet () { return &Timers; }
inline void SetTimeOut (Millisecond t) { TimeOut = t; }
inline void SuppressTimeOut () {TimeOut = -1; }
+ void RegisterSignal (UchBaseSignalHandler&);
+
public:
UchMultiplexer ();
~UchMultiplexer ();