zmachine 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.jrubyrc +732 -0
- data/java/com/liquidm/zmachine/HashedWheel$Timeout.class +0 -0
- data/java/com/liquidm/zmachine/HashedWheel.class +0 -0
- data/java/com/liquidm/zmachine/HashedWheel.java +120 -0
- data/lib/zmachine.rb +4 -4
- data/lib/zmachine/channel.rb +4 -17
- data/lib/zmachine/connection.rb +11 -7
- data/lib/zmachine/connection_manager.rb +33 -24
- data/lib/zmachine/hashed_wheel.rb +2 -67
- data/lib/zmachine/reactor.rb +6 -7
- data/lib/zmachine/tcp_channel.rb +11 -6
- data/spec/channel_spec.rb +3 -13
- data/spec/connection_spec.rb +2 -2
- data/spec/hashed_wheel_spec.rb +16 -20
- data/zmachine.gemspec +1 -1
- metadata +7 -3
data/lib/zmachine/tcp_channel.rb
CHANGED
@@ -8,6 +8,11 @@ require 'zmachine/channel'
|
|
8
8
|
module ZMachine
|
9
9
|
class TCPChannel < Channel
|
10
10
|
|
11
|
+
def initialize
|
12
|
+
super
|
13
|
+
@buffer = Thread.current[:tcp_channel_buffer] ||= ByteBuffer.allocate(1024 * 1024)
|
14
|
+
end
|
15
|
+
|
11
16
|
def selectable_fd
|
12
17
|
@socket
|
13
18
|
end
|
@@ -60,17 +65,17 @@ module ZMachine
|
|
60
65
|
end
|
61
66
|
|
62
67
|
def connected?
|
68
|
+
return false if @socket.is_a?(ServerSocketChannel)
|
63
69
|
@socket.connected?
|
64
70
|
end
|
65
71
|
|
66
72
|
def read_inbound_data
|
67
73
|
ZMachine.logger.debug("zmachine:tcp_channel:#{__method__}", channel: self) if ZMachine.debug
|
68
|
-
buffer
|
69
|
-
buffer
|
70
|
-
|
71
|
-
buffer.
|
72
|
-
|
73
|
-
data = buffer.array[buffer.position...buffer.limit]
|
74
|
+
@buffer.clear
|
75
|
+
raise IOException.new("EOF") if @socket.read(@buffer) == -1
|
76
|
+
@buffer.flip
|
77
|
+
return if @buffer.limit == 0
|
78
|
+
data = java.util.Arrays.copyOfRange(@buffer.array, @buffer.position, @buffer.limit)
|
74
79
|
data = String.from_java_bytes(data) unless @raw
|
75
80
|
data
|
76
81
|
end
|
data/spec/channel_spec.rb
CHANGED
@@ -44,7 +44,7 @@ shared_examples_for "a Channel" do
|
|
44
44
|
|
45
45
|
it 'writes outbound buffers to the socket' do
|
46
46
|
@client.send_data(data)
|
47
|
-
expect(@client.
|
47
|
+
expect(@client.can_send?).to eq(true)
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'receives data sent from the client' do
|
@@ -84,16 +84,6 @@ shared_examples_for "a Channel" do
|
|
84
84
|
expect(channel).to be_closed
|
85
85
|
end
|
86
86
|
|
87
|
-
it 'closes the connection after writing' do
|
88
|
-
@server.accept
|
89
|
-
@client.finish_connecting
|
90
|
-
@client.send_data(data)
|
91
|
-
@client.close(true)
|
92
|
-
expect(@client).to be_connected
|
93
|
-
@client.write_outbound_data
|
94
|
-
expect(@client).not_to be_connected
|
95
|
-
end
|
96
|
-
|
97
87
|
end
|
98
88
|
|
99
89
|
end
|
@@ -135,9 +125,9 @@ describe TCPChannel do
|
|
135
125
|
channel = @server.accept
|
136
126
|
@client.finish_connecting
|
137
127
|
channel.send_data(data)
|
138
|
-
channel.close(true)
|
139
|
-
expect(channel).to be_connected
|
140
128
|
channel.write_outbound_data
|
129
|
+
expect(channel).to be_connected
|
130
|
+
channel.close
|
141
131
|
expect(channel).not_to be_connected
|
142
132
|
expect(@client).to be_connected
|
143
133
|
@client.read_inbound_data
|
data/spec/connection_spec.rb
CHANGED
data/spec/hashed_wheel_spec.rb
CHANGED
@@ -1,19 +1,15 @@
|
|
1
1
|
require 'zmachine/hashed_wheel'
|
2
2
|
|
3
3
|
describe ZMachine::HashedWheel do
|
4
|
-
let(:wheel) { ZMachine::HashedWheel.new(16,
|
5
|
-
|
6
|
-
it 'returns a timeout on add' do
|
7
|
-
expect(wheel.add(0)).to be_instance_of(ZMachine::HashedWheelTimeout)
|
8
|
-
end
|
4
|
+
let(:wheel) { ZMachine::HashedWheel.new(16, 100) }
|
9
5
|
|
10
6
|
it 'adds timeouts to the correct slot' do
|
11
7
|
wheel.add 0
|
12
|
-
wheel.add
|
13
|
-
wheel.add
|
14
|
-
wheel.add
|
15
|
-
wheel.add
|
16
|
-
wheel.add
|
8
|
+
wheel.add 90
|
9
|
+
wheel.add 110
|
10
|
+
wheel.add 1000
|
11
|
+
wheel.add 1600
|
12
|
+
wheel.add 3200
|
17
13
|
expect(wheel.slots[0].length).to eq(4)
|
18
14
|
expect(wheel.slots[1].length).to eq(1)
|
19
15
|
expect(wheel.slots[10].length).to eq(1)
|
@@ -21,19 +17,19 @@ describe ZMachine::HashedWheel do
|
|
21
17
|
|
22
18
|
it 'times out same slot timeouts correctly' do
|
23
19
|
now = wheel.reset
|
24
|
-
wheel.add
|
25
|
-
wheel.add
|
20
|
+
wheel.add 10
|
21
|
+
wheel.add 50
|
26
22
|
timedout = wheel.advance(now + 30 * 1_000_000)
|
27
23
|
expect(timedout.length).to eq(1)
|
28
24
|
end
|
29
25
|
|
30
26
|
it 'calculates the timeout set correctly' do
|
31
27
|
now = wheel.reset
|
32
|
-
wheel.add
|
33
|
-
wheel.add
|
34
|
-
wheel.add
|
35
|
-
wheel.add
|
36
|
-
wheel.add
|
28
|
+
wheel.add 10
|
29
|
+
wheel.add 40
|
30
|
+
wheel.add 1900
|
31
|
+
wheel.add 3300
|
32
|
+
wheel.add 4000
|
37
33
|
timedout = wheel.advance(now + 3900 * 1_000_000)
|
38
34
|
expect(timedout).to be
|
39
35
|
expect(timedout.length).to eq(4)
|
@@ -41,11 +37,11 @@ describe ZMachine::HashedWheel do
|
|
41
37
|
|
42
38
|
it 'cancels timers correctly' do
|
43
39
|
now = wheel.reset
|
44
|
-
t1 = wheel.add
|
45
|
-
t2 = wheel.add
|
40
|
+
t1 = wheel.add 90
|
41
|
+
t2 = wheel.add 110
|
46
42
|
t1.cancel
|
47
43
|
timedout = wheel.advance(now + 200 * 1_000_000)
|
48
|
-
expect(timedout).to eq(
|
44
|
+
expect(timedout.first).to eq(t2)
|
49
45
|
expect(timedout.length).to eq(1)
|
50
46
|
end
|
51
47
|
|
data/zmachine.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "zmachine"
|
5
|
-
spec.version = "0.
|
5
|
+
spec.version = "0.4.0"
|
6
6
|
spec.authors = ["LiquidM, Inc."]
|
7
7
|
spec.email = ["opensource@liquidm.com"]
|
8
8
|
spec.description = %q{pure JRuby multi-threaded mostly EventMachine compatible event loop}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zmachine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- LiquidM, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: liquid-ext
|
@@ -32,6 +32,7 @@ extensions: []
|
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
34
|
- .gitignore
|
35
|
+
- .jrubyrc
|
35
36
|
- .rspec
|
36
37
|
- .ruby-version
|
37
38
|
- .travis.yml
|
@@ -44,6 +45,9 @@ files:
|
|
44
45
|
- benchmarks/zmq_channel.rb
|
45
46
|
- examples/echo_client.rb
|
46
47
|
- examples/echo_server.rb
|
48
|
+
- java/com/liquidm/zmachine/HashedWheel$Timeout.class
|
49
|
+
- java/com/liquidm/zmachine/HashedWheel.class
|
50
|
+
- java/com/liquidm/zmachine/HashedWheel.java
|
47
51
|
- lib/zmachine.rb
|
48
52
|
- lib/zmachine/channel.rb
|
49
53
|
- lib/zmachine/connection.rb
|
@@ -82,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
86
|
version: '0'
|
83
87
|
requirements: []
|
84
88
|
rubyforge_project:
|
85
|
-
rubygems_version: 2.2.
|
89
|
+
rubygems_version: 2.2.2
|
86
90
|
signing_key:
|
87
91
|
specification_version: 4
|
88
92
|
summary: pure JRuby multi-threaded mostly EventMachine compatible event loop
|