async-io 1.24.0 → 1.25.0
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/.travis.yml +5 -0
- data/examples/millions/server.rb +1 -1
- data/gems/nio4r-2.3.gemfile +3 -0
- data/lib/async/io/generic.rb +4 -0
- data/lib/async/io/shared_endpoint.rb +2 -2
- data/lib/async/io/socket.rb +3 -3
- data/lib/async/io/ssl_socket.rb +4 -0
- data/lib/async/io/stream.rb +21 -17
- data/lib/async/io/version.rb +1 -1
- data/spec/async/io/c10k_spec.rb +3 -3
- data/spec/async/io/echo_spec.rb +1 -1
- data/spec/async/io/generic_examples.rb +1 -1
- data/spec/async/io/generic_spec.rb +2 -2
- data/spec/async/io/ssl_server_spec.rb +1 -0
- data/spec/async/io/stream_spec.rb +2 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e01be4ac327bd569ca94ab2dee892e146d09dcba53d07602b01b77362c2601d
|
4
|
+
data.tar.gz: cef6ce9421a1f1d8ce9848390e998c251d2972de5915ed47459f8c5352620aca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3d5506e50c9d3ea3259a87a90943565071317f11d277b08608bbfc35ce5b85441e0521950716cd37f20d56a2591544a376624e9bf8d029c338ce748ecef6c9b
|
7
|
+
data.tar.gz: 45114022177aba3e1caf2680cb49754b1ad511487a4327f66851c30fca4a832255545169c275c1dd387aff6c7c241a3286a5241f77de6d4c89b759fc50ec264e
|
data/.travis.yml
CHANGED
data/examples/millions/server.rb
CHANGED
data/lib/async/io/generic.rb
CHANGED
@@ -86,7 +86,7 @@ module Async
|
|
86
86
|
peer = peer.dup
|
87
87
|
|
88
88
|
task.async do |task|
|
89
|
-
task.annotate "connected to #{peer.inspect}"
|
89
|
+
task.annotate "connected to #{peer.inspect} [#{peer.fileno}]"
|
90
90
|
|
91
91
|
begin
|
92
92
|
yield peer, task
|
@@ -104,7 +104,7 @@ module Async
|
|
104
104
|
end
|
105
105
|
|
106
106
|
def to_s
|
107
|
-
"\#<#{self.class} #{@wrappers.
|
107
|
+
"\#<#{self.class} #{@wrappers.size} descriptors for #{@endpoint}>"
|
108
108
|
end
|
109
109
|
end
|
110
110
|
end
|
data/lib/async/io/socket.rb
CHANGED
@@ -93,7 +93,7 @@ module Async
|
|
93
93
|
|
94
94
|
module Server
|
95
95
|
def accept_each(timeout: nil, task: Task.current)
|
96
|
-
task.annotate "accepting connections #{self.local_address.inspect}"
|
96
|
+
task.annotate "accepting connections #{self.local_address.inspect} [fd=#{self.fileno}]"
|
97
97
|
|
98
98
|
callback = lambda do |io, address|
|
99
99
|
yield io, address, task: task
|
@@ -131,7 +131,7 @@ module Async
|
|
131
131
|
return wrapper, address unless block_given?
|
132
132
|
|
133
133
|
task.async do |task|
|
134
|
-
task.annotate "incoming connection #{address.inspect}"
|
134
|
+
task.annotate "incoming connection #{address.inspect} [fd=#{wrapper.fileno}]"
|
135
135
|
|
136
136
|
begin
|
137
137
|
yield wrapper, address
|
@@ -197,7 +197,7 @@ module Async
|
|
197
197
|
|
198
198
|
begin
|
199
199
|
wrapper.connect(remote_address.to_sockaddr)
|
200
|
-
task.annotate "connected to #{remote_address.inspect}"
|
200
|
+
task.annotate "connected to #{remote_address.inspect} [fd=#{wrapper.fileno}]"
|
201
201
|
rescue Exception
|
202
202
|
wrapper.close
|
203
203
|
raise
|
data/lib/async/io/ssl_socket.rb
CHANGED
data/lib/async/io/stream.rb
CHANGED
@@ -82,13 +82,9 @@ module Async
|
|
82
82
|
# Read at most `size` bytes from the stream. Will avoid reading from the underlying stream if possible.
|
83
83
|
def read_partial(size = nil)
|
84
84
|
return '' if size == 0
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
fill_read_buffer(size > @block_size ? size : @block_size)
|
89
|
-
elsif @read_buffer.empty?
|
90
|
-
fill_read_buffer
|
91
|
-
end
|
85
|
+
|
86
|
+
if !@eof and @read_buffer.empty?
|
87
|
+
fill_read_buffer
|
92
88
|
end
|
93
89
|
|
94
90
|
return consume_read_buffer(size)
|
@@ -215,9 +211,13 @@ module Async
|
|
215
211
|
|
216
212
|
# Returns true if the stream is at file which means there is no more data to be read.
|
217
213
|
def eof?
|
218
|
-
|
214
|
+
return false unless @read_buffer.empty?
|
215
|
+
|
216
|
+
if !@eof
|
217
|
+
fill_read_buffer
|
218
|
+
end
|
219
219
|
|
220
|
-
return @eof
|
220
|
+
return @eof
|
221
221
|
end
|
222
222
|
|
223
223
|
alias eof eof?
|
@@ -238,16 +238,20 @@ module Async
|
|
238
238
|
size = @maximum_read_size
|
239
239
|
end
|
240
240
|
|
241
|
-
if @read_buffer.empty?
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
return true
|
241
|
+
if @read_buffer.empty?
|
242
|
+
if @io.read_nonblock(size, @read_buffer, exception: false)
|
243
|
+
return true
|
244
|
+
end
|
246
245
|
else
|
247
|
-
|
248
|
-
|
249
|
-
|
246
|
+
if chunk = @io.read_nonblock(size, @input_buffer, exception: false)
|
247
|
+
@read_buffer << chunk
|
248
|
+
return true
|
249
|
+
end
|
250
250
|
end
|
251
|
+
|
252
|
+
# else for both cases above:
|
253
|
+
@eof = true
|
254
|
+
return false
|
251
255
|
end
|
252
256
|
|
253
257
|
# Consumes at most `size` bytes from the buffer.
|
data/lib/async/io/version.rb
CHANGED
data/spec/async/io/c10k_spec.rb
CHANGED
@@ -51,13 +51,13 @@ RSpec.describe "echo client/server", if: Process.respond_to?(:fork) do
|
|
51
51
|
Async::IO::Socket.bind(server_address) do |server|
|
52
52
|
server.listen(Socket::SOMAXCONN)
|
53
53
|
|
54
|
-
while connections.
|
54
|
+
while connections.size < repeats
|
55
55
|
peer, address = server.accept
|
56
56
|
connections << peer
|
57
57
|
end
|
58
58
|
end.wait
|
59
59
|
|
60
|
-
puts "Releasing #{connections.
|
60
|
+
puts "Releasing #{connections.size} connections..."
|
61
61
|
|
62
62
|
while connection = connections.pop
|
63
63
|
connection.write(".")
|
@@ -124,7 +124,7 @@ RSpec.describe "echo client/server", if: Process.respond_to?(:fork) do
|
|
124
124
|
|
125
125
|
tasks.each(&:wait)
|
126
126
|
|
127
|
-
expect(responses.
|
127
|
+
expect(responses.size).to be repeats
|
128
128
|
end
|
129
129
|
|
130
130
|
# ensure
|
data/spec/async/io/echo_spec.rb
CHANGED
@@ -66,7 +66,7 @@ RSpec.describe Async::IO::Generic do
|
|
66
66
|
input.wait(1, :read)
|
67
67
|
end
|
68
68
|
|
69
|
-
expect(duration).to be_within(
|
69
|
+
expect(duration).to be_within(100).percent_of(wait_duration)
|
70
70
|
expect(input.read(1024)).to be == message
|
71
71
|
|
72
72
|
input.close
|
@@ -92,7 +92,7 @@ RSpec.describe Async::IO::Generic do
|
|
92
92
|
expect(input.wait(wait_duration, :read)).to be_nil
|
93
93
|
end
|
94
94
|
|
95
|
-
expect(duration).to be_within(
|
95
|
+
expect(duration).to be_within(100).percent_of(wait_duration)
|
96
96
|
|
97
97
|
input.close
|
98
98
|
end
|
@@ -98,7 +98,7 @@ RSpec.describe Async::IO::Stream do
|
|
98
98
|
data = nil
|
99
99
|
|
100
100
|
duration = Async::Clock.measure do
|
101
|
-
data = stream.read(
|
101
|
+
data = stream.read(1024**3)
|
102
102
|
end
|
103
103
|
|
104
104
|
size = data.bytesize / 1024**2
|
@@ -106,7 +106,7 @@ RSpec.describe Async::IO::Stream do
|
|
106
106
|
|
107
107
|
example.reporter.message "Read #{size.round(2)}MB of data at #{rate.round(2)}MB/s."
|
108
108
|
|
109
|
-
expect(rate).to be >
|
109
|
+
expect(rate).to be > 128
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async-io
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.25.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- examples/millions/server.rb
|
136
136
|
- examples/udp/client.rb
|
137
137
|
- examples/udp/server.rb
|
138
|
+
- gems/nio4r-2.3.gemfile
|
138
139
|
- lib/async/io.rb
|
139
140
|
- lib/async/io/address.rb
|
140
141
|
- lib/async/io/address_endpoint.rb
|