]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/socketengines/socketengine_poll.h
Fix a plausible memory leak on rehash, thanks dz.
[user/henk/code/inspircd.git] / include / socketengines / socketengine_poll.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_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 public:
47         /** Create a new PollEngine
48          * @param Instance The creator of this object
49          */
50         PollEngine(InspIRCd* Instance);
51         /** Delete a PollEngine
52          */
53         virtual ~PollEngine();
54         virtual bool AddFd(EventHandler* eh);
55         virtual int GetMaxFds();
56         virtual int GetRemainingFds();
57         virtual bool DelFd(EventHandler* eh, bool force = false);
58         virtual int DispatchEvents();
59         virtual std::string GetName();
60         virtual void WantWrite(EventHandler* eh);
61 };
62
63 /** Creates a SocketEngine
64  */
65 class SocketEngineFactory
66 {
67 public:
68         /** Create a new instance of SocketEngine based on PollEngine
69          */
70         SocketEngine* Create(InspIRCd* Instance) { return new PollEngine(Instance); }
71 };
72
73 #endif