]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/socketengine_select.h
Add irc::dynamicbitmask class. Feel free to take a look and offer suggestions, as...
[user/henk/code/inspircd.git] / include / socketengine_select.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15 */
16
17 #ifndef __SOCKETENGINE_SELECT__
18 #define __SOCKETENGINE_SELECT__
19
20 #include <vector>
21 #include <string>
22 #include <map>
23 #include <sys/select.h>
24 #include "inspircd_config.h"
25 #include "globals.h"
26 #include "inspircd.h"
27 #include "socketengine.h"
28
29 class InspIRCd;
30
31 /** A specialisation of the SocketEngine class, designed to use traditional select().
32  */
33 class SelectEngine : public SocketEngine
34 {
35 private:
36         /** Because select() does not track an fd list for us between calls, we have one of our own
37          */
38         std::map<int,int> fds;
39         /** List of writeable ones (WantWrite())
40          */
41         bool writeable[MAX_DESCRIPTORS];
42         /** The read set and write set, populated before each call to select().
43          */
44         fd_set wfdset, rfdset, errfdset;
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);
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