]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/socketengine_select.h
Not safe for use yet
[user/henk/code/inspircd.git] / include / socketengine_select.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #ifndef __SOCKETENGINE_SELECT__
15 #define __SOCKETENGINE_SELECT__
16
17 #include <vector>
18 #include <string>
19 #include <map>
20 #include <sys/select.h>
21 #include "inspircd_config.h"
22 #include "globals.h"
23 #include "inspircd.h"
24 #include "socketengine.h"
25
26 class InspIRCd;
27
28 /** A specialisation of the SocketEngine class, designed to use traditional select().
29  */
30 class SelectEngine : public SocketEngine
31 {
32 private:
33         /** Because select() does not track an fd list for us between calls, we have one of our own
34          */
35         std::map<int,int> fds;
36         /** List of writeable ones (WantWrite())
37          */
38         bool writeable[MAX_DESCRIPTORS];
39         /** The read set and write set, populated before each call to select().
40          */
41         fd_set wfdset, rfdset, errfdset;
42 public:
43         /** Create a new SelectEngine
44          * @param Instance The creator of this object
45          */
46         SelectEngine(InspIRCd* Instance);
47         /** Delete a SelectEngine
48          */
49         virtual ~SelectEngine();
50         virtual bool AddFd(EventHandler* eh);
51         virtual int GetMaxFds();
52         virtual int GetRemainingFds();
53         virtual bool DelFd(EventHandler* eh, bool force = false);
54         virtual int DispatchEvents();
55         virtual std::string GetName();
56         virtual void WantWrite(EventHandler* eh);
57 };
58
59 /** Creates a SocketEngine
60  */
61 class SocketEngineFactory
62 {
63 public:
64         /** Create a new instance of SocketEngine based on SelectEngine
65          */
66         SocketEngine* Create(InspIRCd* Instance) { return new SelectEngine(Instance); }
67 };
68
69 #endif