spyder 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/spyder/server.rb +49 -42
- data/lib/spyder/version.rb +1 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3417dd82aa219dd2526c0fb01be1f6e9c58723651bac784b2f082a4c8d3b5f20
|
4
|
+
data.tar.gz: eca6629c49c0048f7304da5c71f8701d38b1a24ef4a160f923bf5267d0cea628
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d97926b4bc3a3064d7e6224c0bbb61ec2a225207f766802be5821db8d9b092eba60e92aec37b5012843e073999aa057c79e946551503e680dcf7c2e327013f32
|
7
|
+
data.tar.gz: 51a1d5d5a6b4e8d7ba2598ddcf674e1acb224e35fa77a2c53f90a97f936709bc52274f9f92cef492d93f96ef3095758a7e946e63cc2db7720859a4c654096509
|
data/lib/spyder/server.rb
CHANGED
@@ -4,8 +4,9 @@ module Spyder
|
|
4
4
|
class Server
|
5
5
|
attr_accessor :router
|
6
6
|
|
7
|
-
def initialize(bind, port, router: Router.new, max_threads: 4)
|
7
|
+
def initialize(bind, port, router: Router.new, max_threads: 4, tcp_backlog: 10)
|
8
8
|
@server = TCPServer.new(bind, port)
|
9
|
+
@tcp_backlog = tcp_backlog
|
9
10
|
@max_threads = max_threads
|
10
11
|
@middleware = []
|
11
12
|
@threads = []
|
@@ -18,44 +19,45 @@ module Spyder
|
|
18
19
|
end
|
19
20
|
|
20
21
|
def start
|
21
|
-
|
22
|
-
|
23
|
-
client = @server.accept
|
22
|
+
busy_threads = 0
|
23
|
+
@server.listen(@tcp_backlog)
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
loop do
|
26
|
+
time_start = Process.clock_gettime(:CLOCK_MONOTONIC, :float_second)
|
27
|
+
loop do
|
28
|
+
current_busy = @tp_sync.synchronize { busy_threads }
|
29
|
+
break if current_busy < @max_threads
|
30
|
+
sleep(0)
|
31
|
+
current_time = Process.clock_gettime(:CLOCK_MONOTONIC, :float_second)
|
32
|
+
if (current_time - time_start) > 1.0
|
33
|
+
# puts "Waiting a long time: #{(current_time - time_start)}"
|
34
|
+
sleep 0.2
|
31
35
|
end
|
36
|
+
end
|
32
37
|
|
33
|
-
|
34
|
-
|
38
|
+
client = @server.accept
|
39
|
+
@tp_sync.synchronize { busy_threads += 1 }
|
35
40
|
|
36
|
-
|
37
|
-
|
38
|
-
|
41
|
+
Thread.new do
|
42
|
+
begin
|
43
|
+
error = nil
|
44
|
+
begin
|
45
|
+
process_new_client(client)
|
46
|
+
rescue Exception => e
|
47
|
+
error = e
|
48
|
+
end
|
39
49
|
|
40
|
-
|
41
|
-
|
50
|
+
if error
|
51
|
+
puts error.full_message
|
42
52
|
|
43
|
-
|
44
|
-
|
45
|
-
while over_capacity
|
46
|
-
@tp_sync.synchronize do
|
47
|
-
unless added_thread_to_list
|
48
|
-
@threads << app_thread
|
49
|
-
added_thread_to_list = true
|
53
|
+
response = Response.make_generic :internal_server_error
|
54
|
+
dispatch_response(client, response)
|
50
55
|
end
|
51
|
-
over_capacity = (@threads.length >= @max_threads)
|
52
|
-
# puts("#{@threads.length} of #{@max_threads}")
|
53
56
|
|
54
|
-
|
57
|
+
client.close rescue nil
|
58
|
+
ensure
|
59
|
+
@tp_sync.synchronize { busy_threads -= 1 }
|
55
60
|
end
|
56
|
-
|
57
|
-
# puts("XXX OVER CAPACITY!") if over_capacity
|
58
|
-
sleep 0 if over_capacity
|
59
61
|
end
|
60
62
|
end
|
61
63
|
end
|
@@ -99,19 +101,24 @@ module Spyder
|
|
99
101
|
content_length = response.body.length
|
100
102
|
end
|
101
103
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
104
|
+
begin
|
105
|
+
socket.write("HTTP/1.1 #{response.code} #{response.reason_sentence.b}\r\n")
|
106
|
+
response.headers.ordered.each do |name, value|
|
107
|
+
socket.write("#{name.b}: #{value.b}\r\n")
|
108
|
+
end
|
109
|
+
socket.write("connection: close\r\n") # FIXME:
|
110
|
+
socket.write("content-length: #{content_length}\r\n") if content_length
|
111
|
+
socket.write("\r\n")
|
112
|
+
|
113
|
+
if response.body
|
114
|
+
Array(response.body).each do |part|
|
115
|
+
content = part.respond_to?(:call) ? part.call : part
|
116
|
+
socket.write(content.b)
|
117
|
+
end
|
114
118
|
end
|
119
|
+
rescue Errno::EPIPE
|
120
|
+
# socket closed. So what?
|
121
|
+
socket.close rescue nil
|
115
122
|
end
|
116
123
|
end
|
117
124
|
|
data/lib/spyder/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spyder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- André D. Piske
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mustermann
|