00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef TNT_TNTNET_H
00031 #define TNT_TNTNET_H
00032
00033 #include <tnt/job.h>
00034 #include <tnt/poller.h>
00035 #include <tnt/dispatcher.h>
00036 #include <tnt/maptarget.h>
00037 #include <tnt/scopemanager.h>
00038 #include <cxxtools/condition.h>
00039 #include <cxxtools/mutex.h>
00040 #include <set>
00041 #include <fstream>
00042
00043 namespace tnt
00044 {
00045 class ListenerBase;
00046 class Tntconfig;
00047
00061 class Tntnet
00062 {
00063 friend class Worker;
00064
00065 unsigned minthreads;
00066 unsigned maxthreads;
00067 unsigned long threadstartdelay;
00068 unsigned timersleep;
00069
00070 Jobqueue queue;
00071
00072 static bool stop;
00073 typedef std::set<ListenerBase*> listeners_type;
00074 listeners_type listeners;
00075 static listeners_type allListeners;
00076
00077 cxxtools::AttachedThread pollerthread;
00078 Poller poller;
00079 Dispatcher dispatcher;
00080
00081 ScopeManager scopemanager;
00082 std::string appname;
00083
00084 std::ofstream accessLog;
00085 cxxtools::Mutex accessLogMutex;
00086
00087
00088 Tntnet(const Tntnet&);
00089 Tntnet& operator= (const Tntnet&);
00090
00091 void timerTask();
00092
00093 static cxxtools::Condition timerStopCondition;
00094 static cxxtools::Mutex timeStopMutex;
00095
00096 public:
00098 Tntnet();
00099
00101 void init(const Tntconfig& config);
00105 void listen(const std::string& ipaddr, unsigned short int port);
00109 void sslListen(const std::string& certificateFile, const std::string& keyFile, const std::string& ipaddr, unsigned short int port);
00115 void run();
00116
00118 static void shutdown();
00120 static bool shouldStop() { return stop; }
00121
00123 Jobqueue& getQueue() { return queue; }
00125 Poller& getPoller() { return poller; }
00127 const Dispatcher& getDispatcher() const { return dispatcher; }
00129 ScopeManager& getScopemanager() { return scopemanager; }
00130
00132 unsigned getMinThreads() const { return minthreads; }
00134 void setMinThreads(unsigned n);
00135
00137 unsigned getMaxThreads() const { return maxthreads; }
00139 void setMaxThreads(unsigned n) { maxthreads = n; }
00140
00142 unsigned getTimersleep() const { return timersleep; }
00144 void setTimersleep(unsigned sec) { timersleep = sec; }
00145
00147 unsigned getThreadStartDelay() const { return threadstartdelay; }
00149 void setThreadStartDelay(unsigned sec) { threadstartdelay = sec; }
00150
00152 unsigned getQueueSize() const { return queue.getCapacity(); }
00154 void setQueueSize(unsigned n) { queue.setCapacity(n); }
00155
00159 Maptarget& mapUrl(const std::string& url, const std::string& ci)
00160 { return dispatcher.addUrlMapEntry(std::string(), url, Maptarget(ci)); }
00161 void mapUrl(const std::string& url, const std::string& pathinfo, const std::string& ci_)
00162 {
00163 Maptarget ci(ci_);
00164 ci.setPathInfo(pathinfo);
00165 dispatcher.addUrlMapEntry(std::string(), url, ci);
00166 }
00167 Maptarget& mapUrl(const std::string& url, const Maptarget& ci)
00168 { return dispatcher.addUrlMapEntry(std::string(), url, ci); }
00169 Maptarget& vMapUrl(const std::string& vhost, const std::string& url, const Maptarget& ci)
00170 { return dispatcher.addUrlMapEntry(vhost, url, ci); }
00171
00185 void setAppName(const std::string& appname_)
00186 { appname = appname_; }
00187 const std::string& getAppName() const
00188 { return appname; }
00189
00190 void setAccessLog(const std::string& accesslog)
00191 { accessLog.open(accesslog.c_str(), std::ios::out | std::ios::app); }
00192 };
00193
00194 }
00195
00196 #endif // TNT_TNTNET_H
00197