waitress-core 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/waitress.rb +7 -0
- data/lib/waitress/configure.rb +6 -1
- data/lib/waitress/response.rb +2 -1
- data/lib/waitress/server.rb +63 -37
- data/lib/waitress/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53fac76668e1321e024fed8489d1e3bcf80075e2
|
4
|
+
data.tar.gz: 8cc2c10b4661f3c42a5432eda9504691d1d47bf0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efb9647f241a506830c1a69f18869e2fcc7b67d8dc092ce0b14512445773fb2e8118a9c3c2ad8809e892f48f176588e32e8e510ef6e9aaaa30c73ec44ca2bb08
|
7
|
+
data.tar.gz: fc393bf48cdebecbadc08d8a1dc3ec998443c3ebeb00242065a0bb5c0e03b65f45f670f92c389c8370cfc17d6f1e3f1922fb99d5c3dd2f27286a7c070ff233b0
|
data/lib/waitress.rb
CHANGED
@@ -25,6 +25,13 @@ require 'fileutils'
|
|
25
25
|
# classes and utilities created by Waitress
|
26
26
|
module Waitress
|
27
27
|
|
28
|
+
SERVERS = []
|
29
|
+
|
30
|
+
at_exit do
|
31
|
+
SERVERS.each { |x| x.killall }
|
32
|
+
exit
|
33
|
+
end
|
34
|
+
|
28
35
|
# Create a new Waitress Server, or, in case of the Filesystem, create a Configuration
|
29
36
|
# for a set of Servers
|
30
37
|
# Params:
|
data/lib/waitress/configure.rb
CHANGED
@@ -27,6 +27,7 @@ module Waitress
|
|
27
27
|
@servers = @configurations.map do |conf|
|
28
28
|
s = Waitress::HttpServer.new
|
29
29
|
conf.hosts.each { |h| s << h }
|
30
|
+
s.set_processes conf.processes
|
30
31
|
s.ports *conf.ports
|
31
32
|
s
|
32
33
|
end
|
@@ -82,11 +83,15 @@ module Waitress
|
|
82
83
|
|
83
84
|
attr_accessor :hosts
|
84
85
|
attr_accessor :ports
|
86
|
+
attr_accessor :processes
|
85
87
|
|
86
88
|
def initialize configure, *ports
|
87
89
|
@ports = *ports
|
88
90
|
@hosts = []
|
89
91
|
@configure = configure
|
92
|
+
|
93
|
+
@processes = 10
|
94
|
+
@processes = ENV["WAITRESS_PROCESSES"].to_i if ENV.include? "WAITRESS_PROCESSES"
|
90
95
|
end
|
91
96
|
|
92
97
|
# Create a new VirtualHost with the given regex, priority, and configure it
|
@@ -101,7 +106,7 @@ module Waitress
|
|
101
106
|
|
102
107
|
# Over all the registered VHosts, call this method. Use this to configure
|
103
108
|
# a similar setting for all vhosts at once instead of duplicating code
|
104
|
-
# across all of them.
|
109
|
+
# across all of them.
|
105
110
|
def all_hosts &block
|
106
111
|
@hosts.each { |h| block.call(h) }
|
107
112
|
end
|
data/lib/waitress/response.rb
CHANGED
data/lib/waitress/server.rb
CHANGED
@@ -12,11 +12,22 @@ module Waitress
|
|
12
12
|
attr_accessor :http_body
|
13
13
|
end
|
14
14
|
|
15
|
+
attr_accessor :processes
|
16
|
+
|
15
17
|
# Create a new Server instance with the given ports. If no ports are given,
|
16
18
|
# port 80 will be used as a default
|
17
19
|
def initialize(*ports)
|
20
|
+
Waitress::SERVERS << self
|
18
21
|
ports << 80 if ports.length == 0
|
19
22
|
@ports = ports
|
23
|
+
@processes = 10
|
24
|
+
@processes = ENV["WAITRESS_PROCESSES"].to_i if ENV.include? "WAITRESS_PROCESSES"
|
25
|
+
@running_processes = []
|
26
|
+
end
|
27
|
+
|
28
|
+
# Set the amount of concurrent Waitress Processes to run on this Server, per Port
|
29
|
+
def set_processes count
|
30
|
+
@processes = count
|
20
31
|
end
|
21
32
|
|
22
33
|
# Set or Get the ports for this server. If arguments are provided, the ports
|
@@ -32,16 +43,25 @@ module Waitress
|
|
32
43
|
# set (or 80 for the default)
|
33
44
|
def run *ports
|
34
45
|
@ports = ports unless ports.length == 0
|
35
|
-
@threads = @ports.map { |x| Thread.new { launch_port x } }
|
36
46
|
self.each do |vhost|
|
37
47
|
vhost.on_server_start self
|
38
48
|
end
|
49
|
+
|
50
|
+
@running_processes = @ports.map do |port|
|
51
|
+
launch_port(port)
|
52
|
+
end
|
53
|
+
@running_processes.flatten!
|
39
54
|
self
|
40
55
|
end
|
41
56
|
|
57
|
+
# Killall running processes
|
58
|
+
def killall
|
59
|
+
@running_processes.each { |x| x.kill }
|
60
|
+
end
|
61
|
+
|
42
62
|
# Join the server, blocking the current thread in order to keep the server alive.
|
43
63
|
def join
|
44
|
-
@
|
64
|
+
@running_processes.each { |x| x.wait }
|
45
65
|
end
|
46
66
|
|
47
67
|
# Handle a client based on an IO stream, if you plan to serve on a non-socket
|
@@ -52,48 +72,54 @@ module Waitress
|
|
52
72
|
|
53
73
|
:private
|
54
74
|
def launch_port port
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
75
|
+
serv = TCPServer.new port
|
76
|
+
processes = []
|
77
|
+
@processes.times do
|
78
|
+
processes << gofork {
|
79
|
+
while true
|
80
|
+
begin
|
81
|
+
client = serv.accept
|
82
|
+
handle_client client
|
83
|
+
rescue => e
|
84
|
+
puts "Server Error: #{e} (Fix This!)"
|
85
|
+
puts e.backtrace
|
86
|
+
client.close rescue nil
|
87
|
+
end
|
64
88
|
end
|
65
|
-
|
89
|
+
}
|
66
90
|
end
|
91
|
+
processes
|
67
92
|
end
|
68
93
|
|
69
94
|
def handle_client client_socket
|
70
|
-
gofork do
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
end
|
95
|
+
# pro = gofork do
|
96
|
+
begin
|
97
|
+
data = client_socket.readpartial(8192)
|
98
|
+
nparsed = 0
|
99
|
+
|
100
|
+
parser = Waitress::HttpParser.new
|
101
|
+
params = HttpParams.new
|
102
|
+
|
103
|
+
while nparsed < data.length
|
104
|
+
nparsed = parser.execute(params, data, nparsed)
|
105
|
+
if parser.finished?
|
106
|
+
build_request params, client_socket
|
107
|
+
else
|
108
|
+
ch = client.readpartial(8192)
|
109
|
+
break if !ch or ch.length == 0
|
110
|
+
|
111
|
+
data << ch
|
88
112
|
end
|
89
|
-
rescue EOFError, Errno::ECONNRESET, Errno::EPIPE, Errno::EINVAL, Errno::EBADF
|
90
|
-
client_socket.close rescue nil
|
91
|
-
rescue => e
|
92
|
-
puts "Client Error: #{e}"
|
93
|
-
puts e.backtrace
|
94
113
|
end
|
95
|
-
|
96
|
-
|
114
|
+
rescue EOFError, Errno::ECONNRESET, Errno::EPIPE, Errno::EINVAL, Errno::EBADF
|
115
|
+
client_socket.close rescue nil
|
116
|
+
rescue => e
|
117
|
+
puts "Client Error: #{e}"
|
118
|
+
puts e.backtrace
|
119
|
+
end
|
120
|
+
# end
|
121
|
+
client_socket.close rescue nil
|
122
|
+
# pro.wait
|
97
123
|
end
|
98
124
|
|
99
125
|
def build_request headers, client_socket
|
data/lib/waitress/version.rb
CHANGED