pixelflut 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/TODO.md +3 -1
- data/bin/pxf-server +7 -4
- data/lib/pixelflut/app.rb +1 -0
- data/lib/pixelflut/server.rb +26 -11
- data/lib/pixelflut/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbd5e580104dccc3e1a1123ccc063dde0ae530d7443129bc044e9b73a9c71293
|
4
|
+
data.tar.gz: 6590f3d4f9491a10aec353701cde1f53a26158ba8c655be0952ea3be0129d500
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac78e76fc92be0e1891012cd1d1fe5b0cb5f388f736f75c2a4a193a294ce339cd1763ce2d1dcc055fa997b6feed20a0fba30d57447695cf8512db229fdcd6306
|
7
|
+
data.tar.gz: 20efde215a0528fc028980fa8edc3c8d40a3acff446aeb3f3599ca7cbd69a87dcc1eac135a5d844e2746a58651c011f8f64a38b2c35733029d382d5c832fe8a0
|
data/TODO.md
CHANGED
data/bin/pxf-server
CHANGED
@@ -8,10 +8,10 @@ def options(cfg)
|
|
8
8
|
opts.banner = 'usage: pxf server [options]'
|
9
9
|
opts.separator(nil)
|
10
10
|
opts.separator('valid options:')
|
11
|
-
opts.on('-b', '--bind ADDR', String, 'bind
|
11
|
+
opts.on('-b', '--bind ADDR', String, 'bind address') do |v|
|
12
12
|
cfg.server.host = v
|
13
13
|
end
|
14
|
-
opts.on('-p', '--port PORT', Integer, '
|
14
|
+
opts.on('-p', '--port PORT', Integer, 'bind port(default: 1234)') do |v|
|
15
15
|
cfg.server.port = v
|
16
16
|
end
|
17
17
|
opts.on('-k', '--keep-alive', Float, 'set maximum keep-alive time') do |v|
|
@@ -20,8 +20,11 @@ def options(cfg)
|
|
20
20
|
opts.on('-r', '--read_buffer SIZE', Integer, 'set read buffer size (default: 1024)') do |v|
|
21
21
|
cfg.server.read_buffer_size = v
|
22
22
|
end
|
23
|
-
opts.on('-
|
24
|
-
cfg.server.
|
23
|
+
opts.on('-l', '--peer-limit NUMBER', Integer, 'limit number connections per peer (default: 8)') do |v|
|
24
|
+
cfg.server.peer_limit = v
|
25
|
+
end
|
26
|
+
opts.on('-c', '--command-limit NUMBER', Integer, 'limit of continious processed commands (default: 10)') do |v|
|
27
|
+
cfg.server.command_limit = v
|
25
28
|
end
|
26
29
|
opts.on('-w', '--width WIDTH', Integer, 'set canvas width (default: 800)') do |v|
|
27
30
|
cfg.width = v
|
data/lib/pixelflut/app.rb
CHANGED
data/lib/pixelflut/server.rb
CHANGED
@@ -9,10 +9,19 @@ module Pixelflut
|
|
9
9
|
:port,
|
10
10
|
:keep_alive_time,
|
11
11
|
:read_buffer_size,
|
12
|
-
:
|
12
|
+
:command_limit,
|
13
|
+
:peer_limit
|
13
14
|
) do
|
14
15
|
def self.default
|
15
|
-
new(nil, 1234, 1, 1024, 10)
|
16
|
+
new(nil, 1234, 1, 1024, 10, 8)
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
"bind: #{host}:#{port}"\
|
21
|
+
", keep-alive-time: #{keep_alive_time}"\
|
22
|
+
", read-buffer-size: #{read_buffer_size}"\
|
23
|
+
", command-limit: #{command_limit}"\
|
24
|
+
", peer-limit: #{peer_limit}"
|
16
25
|
end
|
17
26
|
end
|
18
27
|
|
@@ -21,13 +30,14 @@ module Pixelflut
|
|
21
30
|
def initialize(canvas, config = Configuration.default)
|
22
31
|
@canvas, @config = canvas, config
|
23
32
|
@socket, @connections = nil, {}
|
33
|
+
@peers = Hash.new{ |h, k| h[k] = 0 }
|
24
34
|
@ccfg = Connection::Configuration.new(
|
25
35
|
keep_alive_time: config.keep_alive_time,
|
26
36
|
read_buffer_size: config.read_buffer_size,
|
27
|
-
|
37
|
+
command_limit: config.command_limit,
|
28
38
|
canvas: canvas,
|
29
39
|
size_result: "SIZE #{canvas.width} #{canvas.height}\n".freeze,
|
30
|
-
on_end: ->(conn){ @connections.delete(conn) }
|
40
|
+
on_end: ->(conn){ @peers[conn.peeraddr] -= 1 if @connections.delete(conn) }
|
31
41
|
).freeze
|
32
42
|
end
|
33
43
|
|
@@ -50,8 +60,12 @@ module Pixelflut
|
|
50
60
|
|
51
61
|
private
|
52
62
|
|
53
|
-
def create_connection(
|
54
|
-
|
63
|
+
def create_connection(socket)
|
64
|
+
peeraddr = socket.peeraddr(false)[-1]
|
65
|
+
count = @peers[peeraddr] + 1
|
66
|
+
return socket.close if count > @config.peer_limit
|
67
|
+
@peers[peeraddr] = count
|
68
|
+
con = Connection.new(socket, peeraddr, @ccfg)
|
55
69
|
@connections[con] = con
|
56
70
|
end
|
57
71
|
|
@@ -64,16 +78,17 @@ module Pixelflut
|
|
64
78
|
Configuration = Struct.new(
|
65
79
|
:keep_alive_time,
|
66
80
|
:read_buffer_size,
|
67
|
-
:
|
81
|
+
:command_limit,
|
68
82
|
:canvas,
|
69
83
|
:size_result,
|
70
84
|
:on_end,
|
71
85
|
keyword_init: true
|
72
86
|
)
|
73
87
|
|
74
|
-
|
75
|
-
|
76
|
-
|
88
|
+
attr_reader :peeraddr
|
89
|
+
|
90
|
+
def initialize(socket, peeraddr, config)
|
91
|
+
@socket, @peeraddr, @config = socket, peeraddr, config
|
77
92
|
@last_tm, @buffer = Time.now.to_f, ''
|
78
93
|
end
|
79
94
|
|
@@ -126,7 +141,7 @@ module Pixelflut
|
|
126
141
|
end
|
127
142
|
|
128
143
|
def process_loop(index)
|
129
|
-
command_count = @config.
|
144
|
+
command_count = @config.command_limit
|
130
145
|
while process_buffer(index)
|
131
146
|
index = @buffer.index("\n") or return
|
132
147
|
command_count -= 1
|
data/lib/pixelflut/version.rb
CHANGED