-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsocketd_internal.H
More file actions
177 lines (162 loc) · 4.63 KB
/
socketd_internal.H
File metadata and controls
177 lines (162 loc) · 4.63 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*
* config.hpp
*
* Created on: 2011-05-20
* Author: xaxaxa
*/
/*
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 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 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, see <http://www.gnu.org/licenses/>.
* */
#ifndef CONFIG_HPP_
#define CONFIG_HPP_
#include <cpoll/cpoll.H>
#include <rgc.H>
#include <string>
#include <map>
#include <vector>
#include "socketd.H"
#include <delegate.H>
#include <unistd.h>
using namespace std;
namespace socketd
{
class SocketDException: public std::exception
{
public:
string message;
int32_t number;
SocketDException();
SocketDException(int32_t number);
SocketDException(string message, int32_t number = 0);
~SocketDException() throw ();
const char* what() const throw ();
};
struct binding;
struct vhost;
struct listen
{
public:
//user supplied fields
//RGC::Ref<CP::EndPoint> ep;
string host;
string port;
int id;
int backlog;
//internal fields
vector<CP::HANDLE> socks;
int d,t,p;
listen(string host, string port, int id, int backlog = 32) :
host(host), port(port), id(id), backlog(backlog) {
}
listen() :
backlog(32) {
}
};
struct binding
{
public:
//user supplied fields
string httpPath; //path must not have / at the end!!!!!
string httpHost;
string vhostName; //only needs to be filled if put in the "extraBindings" array
int listenID;
//bitmap:
//0: match listenID
//1: match httpPath
//2: match httpHost
int matchLevel;
enum
{
match_listenID = 1, match_httpPath = 2, match_httpHost = 4
};
binding() {
}
binding(int listenID, string httpPath, string httpHost, int matchLevel) :
httpPath(httpPath), httpHost(httpHost), listenID(listenID), matchLevel(matchLevel) {
}
//internal fields
vhost* vh;
};
struct appConnection: public RGC::Object
{
// sock success
typedef Delegate<void(bool)> passConnCB;
appConnection();
virtual void shutDown()=0;
//return values: 0: success; 1: failed; 2: in progress (passConnCB() will be called later)
virtual int passConnection(CP::Socket* s, void* buffer, int buflen, const passConnCB& cb)=0;
virtual ~appConnection();
};
struct vhost: public RGC::Object
{
public:
//user supplied fields
vector<binding> bindings;
string name;
string exepath; //leave blank (length==0) to disable execing and just wait for attachment
/*int requestsPerProcess;
int maxRequestsPerProcess;
int maxProcesses;*/
int processes; //how many processes to spawn (for load balancing)
//at runtime, the # of processes will be rounded up to the nearest multiple
//of the # of socketd threads
int ipcBufSize; //set to 0 to use system default, -1 to use global settings
//for attaching to a running vhost; arbitrary string; leave blank (length==0) to
//disable attachments
string authCookie;
//whether to LD_PRELOAD socketd_proxy.so
bool preload;
bool useShell;
vhost() :
processes(1), ipcBufSize(-1), preload(false), useShell(true) {
}
vhost(const vector<binding>& bindings, string name, string exepath, string authCookie,
bool preload = false, bool shell = true, int processes = 1) :
bindings(bindings), name(name), exepath(exepath), processes(processes),
authCookie(authCookie), preload(preload), useShell(shell) {
}
//internal fields
//vector<int> conns_i; //indexed by thread*processes + curProcess
RGC::Ref<appConnection> attachmentConn; //readonly by threads
//vector<int> curProcess_i;
int _ipcBufSize;
int _processes; //processes per thread
vector<uint8_t*> perCPUData;
bool hasAttachments;
};
static const char* socketd_proxy = "socketd_proxy.so";
class socketd
{
public:
//user supplied fields
vector<listen> listens;
vector<vhost> vhosts;
vector<binding> extraBindings; //vhostName must be filled for these
string unixAddress;
uint8_t** perCPUData;
//format of per-cpu data structures:
//struct {
// appConnection* conns[processes];
// int curProcess;
// int padding;
//} vhostInfo[vhosts];
int ipcBufSize; //<=0 to use system default
int threads;
void run();
//internal fields
vector<binding*> bindings;
socketd() :
ipcBufSize(0), threads((int) sysconf(_SC_NPROCESSORS_CONF)) {
}
};
}
#endif /* CONFIG_HPP_ */