File: selectloop.h

package info (click to toggle)
apt 0.3.10slink11
  • links: PTS
  • area: main
  • in suites: slink
  • size: 2,136 kB
  • ctags: 2,891
  • sloc: cpp: 22,235; sh: 1,656; makefile: 338; perl: 209
file content (101 lines) | stat: -rw-r--r-- 2,620 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// -*- mode: cpp; mode: fold -*-
// Description								/*{{{*/
// $Id: selectloop.h,v 1.2 1998/08/27 04:10:01 jgg Exp $
/* ######################################################################
   
   Select Loop - Class to allow mulitple sockets to be monitored at once
   SelectLoop::Fd - Selectable file descriptor

   These two classes are used to allow multiple FD's to stream data into
   a number of different locations.
   
   Deriving a class from SelectLoop::Fd and overriding Read/Write and 
   Error will allow you to recive data on that particular Fd when it is 
   ready. The procedures will be called whenever select reports that the
   socket is ready.

   The proper procudure for handling signals is to catch the signal
   with AddSignal. AddSignal will allow the signal to interrupt select 
   (it will be remasked after select). If select is interrupted by a signal
   then it will call Signal for each fd. Signal will not be called for 
   signals that did not occure during the select call however.

   ###################################################################### */
									/*}}}*/
// Header section: deity
#ifndef DEITY_SELECTLOOP_H
#define DEITY_SELECTLOOP_H

#ifdef __GNUG__
#pragma interface "deity/selectloop.h"
#endif  

class SelectLoop
{   
   public:   
   
   // Derive to get FD processing abilities
   class Fd
   {
      friend SelectLoop;

      protected:
      Fd *Next;
      
      bool ReadFlag;
      bool WriteFlag;
      bool ErrorFlag;
      bool SignalFlag;
      
      int FileDesc;
      
      virtual bool Read(SelectLoop &) {return false;};
      virtual bool Write(SelectLoop &) {return false;};
      virtual bool Error(SelectLoop &) {return false;};
      virtual bool Signal(SelectLoop &) {return false;};
      virtual void Setup(SelectLoop &) {};

      public:

      Fd(int Fd,bool Read = false, bool Write = false, 
	 bool Error = false, bool Signal = false);
      virtual ~Fd() {};
   };   
 
   private:
   
   // Linked List of FDs
   Fd *List;
   
   // List of signal handlers
   typedef void (*SigHandler)(int);
   struct Sig
   {
      int Signal;
      SigHandler Handler;
   };

   static Sig Signals[10];
   static SigHandler DeathHandlers[10];
   static bool Triged;
   static void SignalHandler(int Signal);
   static void DeathHandler(int Signal);
   
   public:
   
   bool Quit;
   
   // Main loop
   bool Loop();
   
   // List manipulators
   void Add(Fd *FD);
   void AddSignal(int Sig,SigHandler Handler);
   void AddDeathHandler(SigHandler Handler);
   
   // Construct/destruct
   SelectLoop();
   ~SelectLoop();
};

#endif