ione 1.3.0.pre2 → 1.3.0.pre3
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 +5 -5
- data/lib/ione/future.rb +5 -3
- data/lib/ione/io/acceptor.rb +1 -0
- data/lib/ione/io/base_connection.rb +2 -0
- data/lib/ione/io/connection.rb +1 -0
- data/lib/ione/io/io_reactor.rb +6 -6
- data/lib/ione/io/ssl_connection.rb +1 -0
- data/lib/ione/version.rb +1 -1
- data/spec/integration/io_spec.rb +3 -3
- data/spec/integration/ssl_spec.rb +7 -2
- data/spec/ione/byte_buffer_spec.rb +38 -38
- data/spec/ione/future_spec.rb +64 -65
- data/spec/ione/heap_spec.rb +18 -18
- data/spec/ione/io/acceptor_spec.rb +5 -5
- data/spec/ione/io/connection_common.rb +2 -2
- data/spec/ione/io/io_reactor_spec.rb +19 -19
- data/spec/ione/io/ssl_acceptor_spec.rb +3 -3
- data/spec/ione/io/ssl_connection_spec.rb +3 -3
- data/spec/spec_helper.rb +4 -0
- data/spec/support/fake_server.rb +1 -0
- metadata +16 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 78ca22da674434afcf1293e1b7d70bb3f13a0080b7c492f5016fb6f4f2428702
|
4
|
+
data.tar.gz: a50ef526b8a0163a3c2dd116a75d83b48cb6bbb79f80a4cdb0ba9e66c5c2e4b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8eb9100fc86fb57bff7a048f2d97411764df9e00fd5ec5afa921470283161a282686b9fdeea6cccd750b3dce5ea7efce666c9f6b98ef65ec3df2a3076e39c73d
|
7
|
+
data.tar.gz: be2df17439ad63370e7b980ab99e526080e995d65a25c3547fdfbeca34db25548ff6ba9c7b665cb1f7e4d6603d3a33398a16f9628fc5e9ad53f57f3fe9a8c455
|
data/lib/ione/future.rb
CHANGED
@@ -625,6 +625,8 @@ module Ione
|
|
625
625
|
@lock = Mutex.new
|
626
626
|
@state = PENDING_STATE
|
627
627
|
@listeners = []
|
628
|
+
@value = nil
|
629
|
+
@error = nil
|
628
630
|
end
|
629
631
|
|
630
632
|
# Registers a listener that will be called when this future completes,
|
@@ -869,9 +871,9 @@ module Ione
|
|
869
871
|
looping = more = true
|
870
872
|
while more
|
871
873
|
more = false
|
872
|
-
@futures.pop.on_complete do |
|
873
|
-
if
|
874
|
-
await_next(
|
874
|
+
@futures.pop.on_complete do |value, error|
|
875
|
+
if error || @futures.empty? || !looping || !Thread.current.equal?(outer)
|
876
|
+
await_next(value, error)
|
875
877
|
else
|
876
878
|
more = true
|
877
879
|
end
|
data/lib/ione/io/acceptor.rb
CHANGED
@@ -15,10 +15,12 @@ module Ione
|
|
15
15
|
def initialize(host, port, unblocker)
|
16
16
|
@host = host
|
17
17
|
@port = port
|
18
|
+
@io = nil
|
18
19
|
@unblocker = unblocker
|
19
20
|
@state = CONNECTING_STATE
|
20
21
|
@writable = false
|
21
22
|
@lock = Mutex.new
|
23
|
+
@data_listener = nil
|
22
24
|
@write_buffer = ByteBuffer.new
|
23
25
|
@closed_promise = Promise.new
|
24
26
|
end
|
data/lib/ione/io/connection.rb
CHANGED
data/lib/ione/io/io_reactor.rb
CHANGED
@@ -97,7 +97,7 @@ module Ione
|
|
97
97
|
@error_listeners = []
|
98
98
|
@unblocker = Unblocker.new
|
99
99
|
@io_loop = IoLoopBody.new(@unblocker, @options)
|
100
|
-
@scheduler = Scheduler.new
|
100
|
+
@scheduler = Scheduler.new(@options)
|
101
101
|
@lock = Mutex.new
|
102
102
|
end
|
103
103
|
|
@@ -582,8 +582,8 @@ module Ione
|
|
582
582
|
ensure
|
583
583
|
@lock.unlock
|
584
584
|
end
|
585
|
-
timers.each do |
|
586
|
-
|
585
|
+
timers.each do |t|
|
586
|
+
t.fail(CancelledError.new)
|
587
587
|
end
|
588
588
|
nil
|
589
589
|
end
|
@@ -604,8 +604,8 @@ module Ione
|
|
604
604
|
ensure
|
605
605
|
@lock.unlock
|
606
606
|
end
|
607
|
-
expired_timers.each do |
|
608
|
-
|
607
|
+
expired_timers.each do |t|
|
608
|
+
t.fulfill
|
609
609
|
end
|
610
610
|
end
|
611
611
|
end
|
@@ -616,4 +616,4 @@ module Ione
|
|
616
616
|
end
|
617
617
|
end
|
618
618
|
end
|
619
|
-
end
|
619
|
+
end
|
data/lib/ione/version.rb
CHANGED
data/spec/integration/io_spec.rb
CHANGED
@@ -37,7 +37,7 @@ describe 'An IO reactor' do
|
|
37
37
|
fake_server.await_connects(1)
|
38
38
|
fake_server.broadcast('hello world')
|
39
39
|
await { protocol_handler.data.bytesize > 0 }
|
40
|
-
protocol_handler.data.should
|
40
|
+
protocol_handler.data.should eq('hello world')
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'receives data on multiple connections' do
|
@@ -45,7 +45,7 @@ describe 'An IO reactor' do
|
|
45
45
|
fake_server.await_connects(10)
|
46
46
|
fake_server.broadcast('hello world')
|
47
47
|
await { protocol_handlers.all? { |c| c.data.bytesize > 0 } }
|
48
|
-
protocol_handlers.sample.data.should
|
48
|
+
protocol_handlers.sample.data.should eq('hello world')
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -81,7 +81,7 @@ describe 'An IO reactor' do
|
|
81
81
|
socket = TCPSocket.new(ENV['SERVER_HOST'], port)
|
82
82
|
socket.puts('HELLO')
|
83
83
|
result = socket.read(5)
|
84
|
-
result.should
|
84
|
+
result.should eq('HELLO')
|
85
85
|
socket.close
|
86
86
|
end
|
87
87
|
end
|
@@ -49,6 +49,7 @@ describe 'SSL' do
|
|
49
49
|
ssl_context = OpenSSL::SSL::SSLContext.new
|
50
50
|
ssl_context.key = OpenSSL::PKey::RSA.new(ssl_key)
|
51
51
|
ssl_context.cert = OpenSSL::X509::Certificate.new(ssl_cert)
|
52
|
+
ssl_context.tmp_dh_callback = proc { SslSpec::DH_PARAMS }
|
52
53
|
|
53
54
|
f = io_reactor.start
|
54
55
|
f = f.flat_map do
|
@@ -80,8 +81,8 @@ describe 'SSL' do
|
|
80
81
|
end
|
81
82
|
client.write('hello world')
|
82
83
|
response_received.future.value
|
83
|
-
server_received_data.to_s.should
|
84
|
-
client_received_data.to_s.should
|
84
|
+
server_received_data.to_s.should eq('hello world')
|
85
|
+
client_received_data.to_s.should eq('dlrow olleh')
|
85
86
|
end
|
86
87
|
|
87
88
|
it 'fails to send a message when not using encryption' do
|
@@ -95,3 +96,7 @@ describe 'SSL' do
|
|
95
96
|
client.should be_closed
|
96
97
|
end
|
97
98
|
end
|
99
|
+
|
100
|
+
module SslSpec
|
101
|
+
DH_PARAMS = OpenSSL::PKey::DH.new(File.read(File.expand_path('../../resources/dh.pem', __FILE__)))
|
102
|
+
end
|
@@ -15,28 +15,28 @@ module Ione
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'can be initialized with bytes' do
|
18
|
-
described_class.new('hello').length.should
|
18
|
+
described_class.new('hello').length.should eq(5)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
describe '#length/#size/#bytesize' do
|
23
23
|
it 'returns the number of bytes in the buffer' do
|
24
24
|
buffer << 'foo'
|
25
|
-
buffer.length.should
|
25
|
+
buffer.length.should eq(3)
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'is zero initially' do
|
29
|
-
buffer.length.should
|
29
|
+
buffer.length.should eq(0)
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'is aliased as #size' do
|
33
33
|
buffer << 'foo'
|
34
|
-
buffer.size.should
|
34
|
+
buffer.size.should eq(3)
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'is aliased as #bytesize' do
|
38
38
|
buffer << 'foo'
|
39
|
-
buffer.bytesize.should
|
39
|
+
buffer.bytesize.should eq(3)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -67,19 +67,19 @@ module Ione
|
|
67
67
|
end
|
68
68
|
|
69
69
|
it 'stores its bytes as binary' do
|
70
|
-
buffer.append('hällö').length.should
|
71
|
-
buffer.to_s.encoding.should
|
70
|
+
buffer.append('hällö').length.should eq(7)
|
71
|
+
buffer.to_s.encoding.should eq(::Encoding::BINARY)
|
72
72
|
end
|
73
73
|
|
74
74
|
it 'handles appending with multibyte strings' do
|
75
75
|
buffer.append('hello')
|
76
76
|
buffer.append('würld')
|
77
|
-
buffer.to_s.should
|
77
|
+
buffer.to_s.should eq('hellowürld'.force_encoding(::Encoding::BINARY))
|
78
78
|
end
|
79
79
|
|
80
80
|
it 'handles appending with another byte buffer' do
|
81
81
|
buffer.append('hello ').append(ByteBuffer.new('world'))
|
82
|
-
buffer.to_s.should
|
82
|
+
buffer.to_s.should eq('hello world')
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
@@ -105,7 +105,7 @@ module Ione
|
|
105
105
|
b2 = described_class.new
|
106
106
|
b1.append('foo')
|
107
107
|
b2.append('foo')
|
108
|
-
b1.should
|
108
|
+
b1.should eq(b2)
|
109
109
|
end
|
110
110
|
|
111
111
|
it 'is equal to another buffer when both are empty' do
|
@@ -121,7 +121,7 @@ module Ione
|
|
121
121
|
b2 = described_class.new
|
122
122
|
b1.append('foo')
|
123
123
|
b2.append('foo')
|
124
|
-
b1.hash.should
|
124
|
+
b1.hash.should eq(b2.hash)
|
125
125
|
end
|
126
126
|
|
127
127
|
it 'is not equal to the hash code of another buffer with other contents' do
|
@@ -135,26 +135,26 @@ module Ione
|
|
135
135
|
it 'is equal to the hash code of another buffer when both are empty' do
|
136
136
|
b1 = described_class.new
|
137
137
|
b2 = described_class.new
|
138
|
-
b1.hash.should
|
138
|
+
b1.hash.should eq(b2.hash)
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
142
142
|
describe '#to_s' do
|
143
143
|
it 'returns the bytes' do
|
144
|
-
buffer.append('hello world').to_s.should
|
144
|
+
buffer.append('hello world').to_s.should eq('hello world')
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
148
|
describe '#to_str' do
|
149
149
|
it 'returns the bytes' do
|
150
|
-
buffer.append('hello world').to_str.should
|
150
|
+
buffer.append('hello world').to_str.should eq('hello world')
|
151
151
|
end
|
152
152
|
end
|
153
153
|
|
154
154
|
describe '#inspect' do
|
155
155
|
it 'returns the bytes wrapped in ByteBuffer(...)' do
|
156
156
|
buffer.append("\xca\xfe")
|
157
|
-
buffer.inspect.should
|
157
|
+
buffer.inspect.should eq('#<Ione::ByteBuffer: "\xCA\xFE">')
|
158
158
|
end
|
159
159
|
end
|
160
160
|
|
@@ -162,12 +162,12 @@ module Ione
|
|
162
162
|
it 'discards the specified number of bytes from the front of the buffer' do
|
163
163
|
buffer.append('hello world')
|
164
164
|
buffer.discard(4)
|
165
|
-
buffer.should
|
165
|
+
buffer.should eq(ByteBuffer.new('o world'))
|
166
166
|
end
|
167
167
|
|
168
168
|
it 'returns the byte buffer' do
|
169
169
|
buffer.append('hello world')
|
170
|
-
buffer.discard(4).should
|
170
|
+
buffer.discard(4).should eq(ByteBuffer.new('o world'))
|
171
171
|
end
|
172
172
|
|
173
173
|
it 'raises an error if the number of bytes in the buffer is fewer than the number to discard' do
|
@@ -185,14 +185,14 @@ module Ione
|
|
185
185
|
describe '#read' do
|
186
186
|
it 'returns the specified number of bytes, as a string' do
|
187
187
|
buffer.append('hello')
|
188
|
-
buffer.read(4).should
|
188
|
+
buffer.read(4).should eq('hell')
|
189
189
|
end
|
190
190
|
|
191
191
|
it 'removes the bytes from the buffer' do
|
192
192
|
buffer.append('hello')
|
193
193
|
buffer.read(3)
|
194
|
-
buffer.should
|
195
|
-
buffer.read(2).should
|
194
|
+
buffer.should eq(ByteBuffer.new('lo'))
|
195
|
+
buffer.read(2).should eq('lo')
|
196
196
|
end
|
197
197
|
|
198
198
|
it 'raises an error if there are not enough bytes' do
|
@@ -208,22 +208,22 @@ module Ione
|
|
208
208
|
|
209
209
|
it 'returns a string with binary encoding' do
|
210
210
|
buffer.append('hello')
|
211
|
-
buffer.read(4).encoding.should
|
211
|
+
buffer.read(4).encoding.should eq(::Encoding::BINARY)
|
212
212
|
buffer.append('∆')
|
213
|
-
buffer.read(2).encoding.should
|
213
|
+
buffer.read(2).encoding.should eq(::Encoding::BINARY)
|
214
214
|
end
|
215
215
|
end
|
216
216
|
|
217
217
|
describe '#read_int' do
|
218
218
|
it 'returns the first four bytes interpreted as an int' do
|
219
219
|
buffer.append("\xca\xfe\xba\xbe\x01")
|
220
|
-
buffer.read_int.should
|
220
|
+
buffer.read_int.should eq(0xcafebabe)
|
221
221
|
end
|
222
222
|
|
223
223
|
it 'removes the bytes from the buffer' do
|
224
224
|
buffer.append("\xca\xfe\xba\xbe\x01")
|
225
225
|
buffer.read_int
|
226
|
-
buffer.should
|
226
|
+
buffer.should eq(ByteBuffer.new("\x01"))
|
227
227
|
end
|
228
228
|
|
229
229
|
it 'raises an error if there are not enough bytes' do
|
@@ -235,13 +235,13 @@ module Ione
|
|
235
235
|
describe '#read_short' do
|
236
236
|
it 'returns the first two bytes interpreted as a short' do
|
237
237
|
buffer.append("\xca\xfe\x01")
|
238
|
-
buffer.read_short.should
|
238
|
+
buffer.read_short.should eq(0xcafe)
|
239
239
|
end
|
240
240
|
|
241
241
|
it 'removes the bytes from the buffer' do
|
242
242
|
buffer.append("\xca\xfe\x01")
|
243
243
|
buffer.read_short
|
244
|
-
buffer.should
|
244
|
+
buffer.should eq(ByteBuffer.new("\x01"))
|
245
245
|
end
|
246
246
|
|
247
247
|
it 'raises an error if there are not enough bytes' do
|
@@ -253,14 +253,14 @@ module Ione
|
|
253
253
|
describe '#read_byte' do
|
254
254
|
it 'returns the first bytes interpreted as an int' do
|
255
255
|
buffer.append("\x10\x01")
|
256
|
-
buffer.read_byte.should
|
257
|
-
buffer.read_byte.should
|
256
|
+
buffer.read_byte.should eq(0x10)
|
257
|
+
buffer.read_byte.should eq(0x01)
|
258
258
|
end
|
259
259
|
|
260
260
|
it 'removes the byte from the buffer' do
|
261
261
|
buffer.append("\x10\x01")
|
262
262
|
buffer.read_byte
|
263
|
-
buffer.should
|
263
|
+
buffer.should eq(ByteBuffer.new("\x01"))
|
264
264
|
end
|
265
265
|
|
266
266
|
it 'raises an error if there are no bytes' do
|
@@ -269,8 +269,8 @@ module Ione
|
|
269
269
|
|
270
270
|
it 'can interpret the byte as signed' do
|
271
271
|
buffer.append("\x81\x02")
|
272
|
-
buffer.read_byte(true).should
|
273
|
-
buffer.read_byte(true).should
|
272
|
+
buffer.read_byte(true).should eq(-127)
|
273
|
+
buffer.read_byte(true).should eq(2)
|
274
274
|
end
|
275
275
|
end
|
276
276
|
|
@@ -278,14 +278,14 @@ module Ione
|
|
278
278
|
it 'changes the bytes at the specified location' do
|
279
279
|
buffer.append('foo bar')
|
280
280
|
buffer.update(4, 'baz')
|
281
|
-
buffer.to_s.should
|
281
|
+
buffer.to_s.should eq('foo baz')
|
282
282
|
end
|
283
283
|
|
284
284
|
it 'handles updates after a read' do
|
285
285
|
buffer.append('foo bar')
|
286
286
|
buffer.read(1)
|
287
287
|
buffer.update(3, 'baz')
|
288
|
-
buffer.to_s.should
|
288
|
+
buffer.to_s.should eq('oo baz')
|
289
289
|
end
|
290
290
|
|
291
291
|
it 'handles updates after multiple reads and appends' do
|
@@ -295,7 +295,7 @@ module Ione
|
|
295
295
|
buffer.update(4, 'baz')
|
296
296
|
buffer.append('yyyy')
|
297
297
|
buffer.read(1)
|
298
|
-
buffer.to_s.should
|
298
|
+
buffer.to_s.should eq('o bbazyyyy')
|
299
299
|
end
|
300
300
|
|
301
301
|
it 'returns itself' do
|
@@ -388,12 +388,12 @@ module Ione
|
|
388
388
|
describe '#index' do
|
389
389
|
it 'returns the first index of the specified substring' do
|
390
390
|
buffer.append('fizz buzz')
|
391
|
-
buffer.index('zz').should
|
391
|
+
buffer.index('zz').should eq(2)
|
392
392
|
end
|
393
393
|
|
394
394
|
it 'returns the first index of the specified substring, after the specified index' do
|
395
395
|
buffer.append('fizz buzz')
|
396
|
-
buffer.index('zz', 3).should
|
396
|
+
buffer.index('zz', 3).should eq(7)
|
397
397
|
end
|
398
398
|
|
399
399
|
it 'returns nil when the substring is not found' do
|
@@ -405,14 +405,14 @@ module Ione
|
|
405
405
|
buffer.append('foo bar')
|
406
406
|
buffer.read(1)
|
407
407
|
buffer.append(' baz baz')
|
408
|
-
buffer.index('baz', 8).should
|
408
|
+
buffer.index('baz', 8).should eq(11)
|
409
409
|
end
|
410
410
|
|
411
411
|
it 'returns the first index when the matching substring spans the read and write buffer' do
|
412
412
|
buffer.append('foo bar')
|
413
413
|
buffer.read(1)
|
414
414
|
buffer.append('bar barbar')
|
415
|
-
buffer.index('barbar', 0).should
|
415
|
+
buffer.index('barbar', 0).should eq(3)
|
416
416
|
end
|
417
417
|
|
418
418
|
it 'returns nil when the substring does not fit in the search space' do
|