1 /**
2 	Classes for controlling the child processes.
3 
4 	Copyright: © 2012-2013 RejectedSoftware e.K.
5 	License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file.
6 	Authors: Sönke Ludwig
7 */
8 module vibedist.engine;
9 
10 import vibe.http.proxy;
11 import vibe.http.server;
12 
13 version(Posix)
14 {
15 	import core.sys.posix.signal;
16 }
17 
18 class Node : HTTPServerRequestHandler {
19 	string address;
20 	ushort port;
21 	HTTPServerRequestDelegate requestHandler;
22 	int pendingRequests = 0;
23 	int pid;
24 	bool active = true;
25 
26 
27 	this(string address, ushort port, int pid)
28 	{
29 		this.address = address;
30 		this.port = port;
31 		this.pid = pid;
32 		requestHandler = reverseProxyRequest(address, port);
33 	}
34 
35 	void handleRequest(HTTPServerRequest req, HTTPServerResponse res)
36 	{
37 		pendingRequests++;
38 		scope(exit) pendingRequests--;
39 		requestHandler(req, res);
40 	}
41 
42 	void kill()
43 	{
44 		version(Posix){
45 			.kill(pid, SIGTERM);
46 		} else {
47 			assert(false);
48 		}
49 	}
50 }
51 
52 class PublicInterface : HTTPServerRequestHandler {
53 	HTTPServerSettings settings;
54 	string path;
55 	Node[] nodes;
56 
57 	void handleRequest(HTTPServerRequest req, HTTPServerResponse res)
58 	{
59 		nodes[0].handleRequest(req, res);
60 	}
61 }
62 
63 PublicInterface[] g_interfaces;
64