diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-07-19 12:51:21 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-07-19 12:51:21 +0000 |
commit | 3a6885d6a1d30f6e2eb9b1fcd20e949768267318 (patch) | |
tree | fefc6fb26bf91713479e47261775651c927b1441 /include | |
parent | e8c920ce01a47e7b05ca3d445c3d8d88f9c70e37 (diff) |
* Seperate out socket engines into derived classes of SocketEngine.
* Add a classfactory SocketEngineFactory to create a new socketengine of the configured type
* Implement configure hax to compile only the required socketengine and the base class
* Eliminates ugly defines, and is more in line with C++ ways
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4439 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'include')
-rw-r--r-- | include/aes.h | 1 | ||||
-rw-r--r-- | include/inspsocket.h | 2 | ||||
-rw-r--r-- | include/socketengine.h | 38 | ||||
-rw-r--r-- | include/socketengine_epoll.h | 51 | ||||
-rw-r--r-- | include/socketengine_kqueue.h | 53 | ||||
-rw-r--r-- | include/socketengine_select.h | 50 |
6 files changed, 165 insertions, 30 deletions
diff --git a/include/aes.h b/include/aes.h index 53e4bd181..b14338e7a 100644 --- a/include/aes.h +++ b/include/aes.h @@ -2,6 +2,7 @@ #define __AES_H__
#include <cstring>
+#include "inspircd_config.h"
#include "base.h"
using namespace std;
diff --git a/include/inspsocket.h b/include/inspsocket.h index 56c04373d..4bd76788c 100644 --- a/include/inspsocket.h +++ b/include/inspsocket.h @@ -20,8 +20,8 @@ #include <sstream> #include <string> #include <deque> -#include "inspircd_config.h" #include "dns.h" +#include "inspircd_config.h" #include "socket.h" /** diff --git a/include/socketengine.h b/include/socketengine.h index e07642fa1..734aa1938 100644 --- a/include/socketengine.h +++ b/include/socketengine.h @@ -23,15 +23,6 @@ #include "inspircd_config.h" #include "globals.h" #include "inspircd.h" -#ifdef USE_EPOLL -#include <sys/epoll.h> -#define EP_DELAY 5 -#endif -#ifdef USE_KQUEUE -#include <sys/types.h> -#include <sys/event.h> -#include <sys/time.h> -#endif /** * Each of these values represents a socket @@ -67,21 +58,10 @@ const char X_READBIT = 0x80; */ class SocketEngine : public Extensible { - +protected: int EngineHandle; /* Handle to the socket engine if needed */ int CurrentSetSize; /* Current number of descriptors in the engine */ -#ifdef USE_SELECT - std::map<int,int> fds; /* List of file descriptors being monitored */ - fd_set wfdset, rfdset; /* Readable and writeable sets for select() */ -#endif -#ifdef USE_KQUEUE - struct kevent ke_list[MAX_DESCRIPTORS]; /* Up to 64k sockets for kqueue */ - struct timespec ts; /* kqueue delay value */ -#endif -#ifdef USE_EPOLL - struct epoll_event events[MAX_DESCRIPTORS]; /* Up to 64k sockets for epoll */ -#endif - + char ref[MAX_DESCRIPTORS]; /* Reference table */ public: /** Constructor @@ -98,7 +78,7 @@ public: * The destructor transparently tidies up * any resources used by the socket engine. */ - ~SocketEngine(); + virtual ~SocketEngine(); /** Add a file descriptor to the engine * Use AddFd to add a file descriptor to the @@ -109,7 +89,7 @@ public: * or write events (there is currently no * need for support of both). */ - bool AddFd(int fd, bool readable, char type); + virtual bool AddFd(int fd, bool readable, char type); /** Returns the type value for this file descriptor * This function masks off the X_READBIT value @@ -126,19 +106,19 @@ public: /** Returns the maximum number of file descriptors * you may store in the socket engine at any one time. */ - int GetMaxFds(); + virtual int GetMaxFds(); /** Returns the number of file descriptor slots * which are available for storing fds. */ - int GetRemainingFds(); + virtual int GetRemainingFds(); /** Delete a file descriptor from the engine * This function call deletes a file descriptor * from the engine, returning true if it succeeded * and false if it failed. */ - bool DelFd(int fd); + virtual bool DelFd(int fd); /** Returns true if a socket exists in the socket * engine's list. @@ -151,13 +131,13 @@ public: * of active file descriptors in the vector * fdlist which the core may then act upon. */ - int Wait(int* fdlist); + virtual int Wait(int* fdlist); /** Returns the socket engines name * This returns the name of the engine for use * in /VERSION responses. */ - std::string GetName(); + virtual std::string GetName(); }; #endif diff --git a/include/socketengine_epoll.h b/include/socketengine_epoll.h new file mode 100644 index 000000000..ddbeb6f40 --- /dev/null +++ b/include/socketengine_epoll.h @@ -0,0 +1,51 @@ +/* +------------------------------------+ + * | Inspire Internet Relay Chat Daemon | + * +------------------------------------+ + * + * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev. + * E-mail: + * <brain@chatspike.net> + * <Craig@chatspike.net> + * + * Written by Craig Edwards, Craig McLure, and others. + * This program is free but copyrighted software; see + * the file COPYING for details. + * + * --------------------------------------------------- +*/ + +#ifndef __SOCKETENGINE_EPOLL__ +#define __SOCKETENGINE_EPOLL__ + +#include <vector> +#include <string> +#include <map> +#include "inspircd_config.h" +#include "globals.h" +#include "inspircd.h" +#include "socketengine.h" +#include <sys/epoll.h> +#define EP_DELAY 5 + +class EPollEngine : public SocketEngine +{ +private: + struct epoll_event events[MAX_DESCRIPTORS]; /* Up to 64k sockets for epoll */ +public: + EPollEngine(); + virtual ~EPollEngine(); + virtual bool AddFd(int fd, bool readable, char type); + virtual int GetMaxFds(); + virtual int GetRemainingFds(); + virtual bool DelFd(int fd); + virtual int Wait(int* fdlist); + virtual std::string GetName(); +}; + +class SocketEngineFactory +{ +public: + SocketEngine* Create() { return new EPollEngine(); } +}; + +#endif diff --git a/include/socketengine_kqueue.h b/include/socketengine_kqueue.h new file mode 100644 index 000000000..6de6a0552 --- /dev/null +++ b/include/socketengine_kqueue.h @@ -0,0 +1,53 @@ +/* +------------------------------------+ + * | Inspire Internet Relay Chat Daemon | + * +------------------------------------+ + * + * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev. + * E-mail: + * <brain@chatspike.net> + * <Craig@chatspike.net> + * + * Written by Craig Edwards, Craig McLure, and others. + * This program is free but copyrighted software; see + * the file COPYING for details. + * + * --------------------------------------------------- +*/ + +#ifndef __SOCKETENGINE_KQUEUE__ +#define __SOCKETENGINE_KQUEUE__ + +#include <vector> +#include <string> +#include <map> +#include "inspircd_config.h" +#include "globals.h" +#include "inspircd.h" +#include <sys/types.h> +#include <sys/event.h> +#include <sys/time.h> +#include "socketengine.h" + +class KQueueEngine : public SocketEngine +{ +private: + struct kevent ke_list[MAX_DESCRIPTORS]; /* Up to 64k sockets for kqueue */ + struct timespec ts; /* kqueue delay value */ +public: + KQueueEngineEngine(); + virtual ~KQueueEngine(); + virtual bool AddFd(int fd, bool readable, char type); + virtual int GetMaxFds(); + virtual int GetRemainingFds(); + virtual bool DelFd(int fd); + virtual int Wait(int* fdlist); + virtual std::string GetName(); +}; + +class SocketEngineFactory +{ + public: + SocketEngine* Create() { return new KQueueEngine(); } +}; + +#endif diff --git a/include/socketengine_select.h b/include/socketengine_select.h new file mode 100644 index 000000000..bbd9b78dd --- /dev/null +++ b/include/socketengine_select.h @@ -0,0 +1,50 @@ +/* +------------------------------------+ + * | Inspire Internet Relay Chat Daemon | + * +------------------------------------+ + * + * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev. + * E-mail: + * <brain@chatspike.net> + * <Craig@chatspike.net> + * + * Written by Craig Edwards, Craig McLure, and others. + * This program is free but copyrighted software; see + * the file COPYING for details. + * + * --------------------------------------------------- +*/ + +#ifndef __SOCKETENGINE_SELECT__ +#define __SOCKETENGINE_SELECT__ + +#include <vector> +#include <string> +#include <map> +#include "inspircd_config.h" +#include "globals.h" +#include "inspircd.h" +#include "socketengine.h" + +class SelectEngine : public SocketEngine +{ +private: + std::map<int,int> fds; /* List of file descriptors being monitored */ + fd_set wfdset, rfdset; /* Readable and writeable sets for select() */ +public: + SelectEngine(); + virtual ~SelectEngine(); + virtual bool AddFd(int fd, bool readable, char type); + virtual int GetMaxFds(); + virtual int GetRemainingFds(); + virtual bool DelFd(int fd); + virtual int Wait(int* fdlist); + virtual std::string GetName(); +}; + +class SocketEngineFactory +{ +public: + SocketEngine* Create() { return new SelectEngine(); } +}; + +#endif |