00001
00002
00003 #ifndef BASE_MTSOCKETDAEMON_H
00004 #define BASE_MTSOCKETDAEMON_H
00005
00006 #ifndef _WIN32
00007 #include <sys/poll.h>
00008 #endif
00009 #include "Daemon.h"
00010 #include "Socket.h"
00011 #include "ThreadList.h"
00012 #include "WorkPile.h"
00013
00014 namespace base {
00015 class WorkerThread;
00016
00018
00022 class PPBASE_EXPORT MTSocketDaemon: public Daemon {
00023 public:
00025 virtual ~MTSocketDaemon();
00026
00028
00031 int getClientTimeout() const;
00032
00034
00037 size_t getNumberOfActiveThreads();
00038
00040
00043 size_t getNumberOfConnections();
00044
00046
00049 size_t getNumberOfThreads();
00050
00052
00055 int getMaxNumberOfThreads() const;
00056
00058
00061 WorkPile<Socket*> *getWebQueue();
00062
00064
00067 WorkPile<Socket*> *getWorkerQueue();
00068
00070
00073 ThreadList *getWorkerThreads();
00074
00075 protected:
00077
00080 MTSocketDaemon(const String &name);
00081
00083 void closeSockets();
00084
00086 virtual void config();
00087
00089 virtual void createThreads(bool init);
00090
00092
00096 virtual WorkerThread *createWorkerThread(time_t lifetime, bool web = false) = 0;
00097
00099
00104 bool dumpState(bool force);
00105
00107
00111 virtual void handler(Socket::socket_type fd, int what);
00112
00114
00117 virtual int loop();
00118
00120
00123 virtual bool needRootPrivileges();
00124
00126 void openSockets();
00127
00129 virtual void terminateThreads();
00130
00131 int _children;
00132 WorkPile<Socket*> _clientqueue;
00133 int _clienttimeout;
00134 int _fdtype[8];
00135 size_t _nfds;
00136 int _port;
00137 int _sslport;
00138 int _sslwebport;
00139 ThreadList _threads;
00140 bool _threads_waitexit;
00141 int _udpport;
00142 int _webport;
00143 int _web_lifetime;
00144 int _web_max;
00145 int _web_min;
00146 int _web_start;
00147 WorkPile<Socket*> _webqueue;
00148 int _worker_lifetime;
00149 int _worker_max;
00150 int _worker_min;
00151 int _worker_start;
00152 ThreadList _workerthreads;
00153
00154 #ifdef _WIN32
00155 Socket::socket_type _fd[8];
00156 #else
00157 struct pollfd _fd[8];
00158 String _unixsocket;
00159 #endif
00160 };
00161 }
00162
00163 #endif