1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
/* tnt/tntnet.h
* Copyright (C) 2003-2005 Tommi Maekitalo
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* is provided AS IS, WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and
* NON-INFRINGEMENT. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef TNT_TNTNET_H
#define TNT_TNTNET_H
#include <cxxtools/arg.h>
#include "tnt/tntconfig.h"
#include "tnt/job.h"
#include "tnt/poller.h"
#include "tnt/dispatcher.h"
#include <tnt/scopemanager.h>
#include <set>
namespace tnt
{
class ListenerBase;
class Tntnet
{
std::string configFile;
Tntconfig config;
cxxtools::Arg<const char*> propertyfilename;
cxxtools::Arg<bool> debug;
bool isDaemon;
unsigned minthreads;
unsigned maxthreads;
unsigned long threadstartdelay;
Jobqueue queue;
static bool stop;
static int ret;
typedef std::set<ListenerBase*> listeners_type;
listeners_type listeners;
Poller pollerthread;
Dispatcher d_dispatcher;
static std::string pidFileName;
ScopeManager scopemanager;
// helper methods
void setUser() const;
void setGroup() const;
void setDir(const char* def) const;
int mkDaemon() const; // returns pipe
void closeStdHandles() const;
// noncopyable
Tntnet(const Tntnet&);
Tntnet& operator= (const Tntnet&);
void initLogging();
void writePidfile(int pid);
void monitorProcess(int workerPid);
void initWorkerProcess();
void workerProcess(int filedes = -1);
void timerTask();
void loadConfiguration();
public:
Tntnet(int& argc, char* argv[]);
int run();
static void shutdown();
static void restart();
static bool shouldStop() { return stop; }
Jobqueue& getQueue() { return queue; }
Poller& getPoller() { return pollerthread; }
const Dispatcher& getDispatcher() const { return d_dispatcher; }
const Tntconfig& getConfig() const { return config; }
ScopeManager& getScopemanager() { return scopemanager; }
};
}
#endif // TNT_TNTNET_H
|