]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/socketengines/socketengine_poll.h
df1100d095fb78cf2991d9c488adc6ee00f621b4
[user/henk/code/inspircd.git] / include / socketengines / socketengine_poll.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #ifndef __SOCKETENGINE_POLL__
15 #define __SOCKETENGINE_POLL__
16
17 #include <vector>
18 #include <string>
19 #include <map>
20 #include "inspircd_config.h"
21 #include "inspircd.h"
22 #include "socketengine.h"
23
24 #ifndef WINDOWS
25         #ifndef __USE_XOPEN
26             #define __USE_XOPEN /* fuck every fucking OS ever made. needed by poll.h to work.*/
27         #endif
28         #include <poll.h>
29         #include <sys/poll.h>
30 #else
31         /* *grumble* */
32         #define struct pollfd WSAPOLLFD
33         #define poll WSAPoll
34 #endif
35
36 class InspIRCd;
37
38 /** A specialisation of the SocketEngine class, designed to use poll().
39  */
40 class PollEngine : public SocketEngine
41 {
42 private:
43         /** These are used by poll() to hold socket events
44          */
45         struct pollfd *events;
46         /** This map maps fds to an index in the events array.
47          */
48         std::map<int, unsigned int> fd_mappings;
49 public:
50         /** Create a new PollEngine
51          * @param Instance The creator of this object
52          */
53         PollEngine(InspIRCd* Instance);
54         /** Delete a PollEngine
55          */
56         virtual ~PollEngine();
57         virtual bool AddFd(EventHandler* eh);
58         virtual EventHandler* GetRef(int fd);
59         virtual int GetMaxFds();
60         virtual int GetRemainingFds();
61         virtual bool DelFd(EventHandler* eh, bool force = false);
62         virtual int DispatchEvents();
63         virtual std::string GetName();
64         virtual void WantWrite(EventHandler* eh);
65 };
66
67 /** Creates a SocketEngine
68  */
69 class SocketEngineFactory
70 {
71 public:
72         /** Create a new instance of SocketEngine based on PollEngine
73          */
74         SocketEngine* Create(InspIRCd* Instance) { return new PollEngine(Instance); }
75 };
76
77 #endif