]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/socketengines/socketengine_select.h
cb4ed0ecf6f88f544856a743a8f396d7a0691c49
[user/henk/code/inspircd.git] / include / socketengines / socketengine_select.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 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 #ifndef WINDOWS
21 #include <sys/select.h>
22 #endif // WINDOWS
23 #include "inspircd_config.h"
24 #include "globals.h"
25 #include "inspircd.h"
26 #include "socketengine.h"
27
28 class InspIRCd;
29
30 /** A specialisation of the SocketEngine class, designed to use traditional select().
31  */
32 class SelectEngine : public SocketEngine
33 {
34 private:
35         /** Because select() does not track an fd list for us between calls, we have one of our own
36          */
37         std::map<int,int> fds;
38         /** List of writeable ones (WantWrite())
39          */
40         bool* writeable;
41         /** The read set and write set, populated before each call to select().
42          */
43         fd_set wfdset, rfdset, errfdset;
44
45 public:
46         /** Create a new SelectEngine
47          * @param Instance The creator of this object
48          */
49         SelectEngine(InspIRCd* Instance);
50         /** Delete a SelectEngine
51          */
52         virtual ~SelectEngine();
53         virtual bool AddFd(EventHandler* eh);
54         virtual int GetMaxFds();
55         virtual int GetRemainingFds();
56         virtual bool DelFd(EventHandler* eh, bool force = false);
57         virtual int DispatchEvents();
58         virtual std::string GetName();
59         virtual void WantWrite(EventHandler* eh);
60 };
61
62 /** Creates a SocketEngine
63  */
64 class SocketEngineFactory
65 {
66 public:
67         /** Create a new instance of SocketEngine based on SelectEngine
68          */
69         SocketEngine* Create(InspIRCd* Instance) { return new SelectEngine(Instance); }
70 };
71
72 #endif