async-io 1.12.2 → 1.12.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.editorconfig +5 -0
- data/.travis.yml +1 -1
- data/async-io.gemspec +1 -1
- data/examples/allocations.rb +19 -0
- data/examples/chat/server.rb +8 -7
- data/lib/async/io/stream.rb +12 -12
- data/lib/async/io/version.rb +1 -1
- data/spec/async/io/stream_spec.rb +29 -8
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c10de5ece88f5f8366c2560647ab2cc061c12d49790cf1f3aafb6516d0fd7ad4
|
4
|
+
data.tar.gz: c970a916f8e637098bf85a842d27709cb34dae68ded5386451be3f433673d12e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab731c4a8ec3e2f9a3b459e62391a5294b2234ca0a62cf066f435ba33324f174f60676660924cba2ef25c8fae00fb85bb2b4556c4c96cecdbdd1bd7e9c798f35
|
7
|
+
data.tar.gz: 12c30f60cc9e1859664a79d9d6378c690d0756234410699ae79d5fbd837f014ccc10811ff4feb7ec38cda025fe300cac95051aaff5015808ec595a7107c2d426
|
data/.editorconfig
ADDED
data/.travis.yml
CHANGED
data/async-io.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.has_rdoc = "yard"
|
18
18
|
|
19
19
|
spec.add_dependency "async", "~> 1.3"
|
20
|
-
spec.add_development_dependency "async-rspec", "~> 1.
|
20
|
+
spec.add_development_dependency "async-rspec", "~> 1.7"
|
21
21
|
|
22
22
|
spec.required_ruby_version = '~> 2.3'
|
23
23
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative "../lib/async/io/stream"
|
4
|
+
# require "async/io/stream"
|
5
|
+
require "stringio"
|
6
|
+
|
7
|
+
io = StringIO.new("a" * (50*1024*1024))
|
8
|
+
stream = Async::IO::Stream.new(io)
|
9
|
+
|
10
|
+
GC.disable
|
11
|
+
|
12
|
+
start_memory = `ps -p #{Process::pid} -o rss`.split("\n")[1].chomp.to_i
|
13
|
+
|
14
|
+
while (chunk = stream.read_partial)
|
15
|
+
chunk.clear
|
16
|
+
end
|
17
|
+
|
18
|
+
end_memory = `ps -p #{Process::pid} -o rss`.split("\n")[1].chomp.to_i
|
19
|
+
puts "#{(end_memory - start_memory).to_f / 1024} MB"
|
data/examples/chat/server.rb
CHANGED
@@ -22,8 +22,7 @@ class User < Async::IO::Protocol::Line
|
|
22
22
|
end
|
23
23
|
|
24
24
|
class Server
|
25
|
-
def initialize
|
26
|
-
@endpoint = endpoint
|
25
|
+
def initialize
|
27
26
|
@users = Set.new
|
28
27
|
end
|
29
28
|
|
@@ -61,9 +60,9 @@ class Server
|
|
61
60
|
broadcast("#{user} has disconnected: #{reason}")
|
62
61
|
end
|
63
62
|
|
64
|
-
def run
|
63
|
+
def run(endpoint)
|
65
64
|
Async::Reactor.run do |task|
|
66
|
-
|
65
|
+
endpoint.accept do |peer|
|
67
66
|
stream = Async::IO::Stream.new(peer)
|
68
67
|
user = User.new(stream)
|
69
68
|
|
@@ -75,7 +74,9 @@ class Server
|
|
75
74
|
end
|
76
75
|
end
|
77
76
|
|
78
|
-
|
79
|
-
|
77
|
+
Async.logger.level = Logger::INFO
|
78
|
+
Async.logger.info("Starting server...")
|
79
|
+
server = Server.new
|
80
80
|
|
81
|
-
|
81
|
+
endpoint = Async::IO::Endpoint.parse(ARGV.pop || "tcp://localhost:7138")
|
82
|
+
server.run(endpoint)
|
data/lib/async/io/stream.rb
CHANGED
@@ -39,6 +39,9 @@ module Async
|
|
39
39
|
|
40
40
|
@read_buffer = BinaryString.new
|
41
41
|
@write_buffer = BinaryString.new
|
42
|
+
|
43
|
+
# Used as destination buffer for underlying reads.
|
44
|
+
@input_buffer = BinaryString.new
|
42
45
|
end
|
43
46
|
|
44
47
|
attr :io
|
@@ -180,19 +183,16 @@ module Async
|
|
180
183
|
|
181
184
|
# Fills the buffer from the underlying stream.
|
182
185
|
def fill_read_buffer
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
return true
|
187
|
-
end
|
188
|
-
elsif chunk = @io.read(@block_size)
|
186
|
+
if @read_buffer.empty? and @io.read(@block_size, @read_buffer)
|
187
|
+
return true
|
188
|
+
elsif chunk = @io.read(@block_size, @input_buffer)
|
189
189
|
@read_buffer << chunk
|
190
190
|
return true
|
191
|
+
else
|
192
|
+
# We didn't read anything, so we must be at eof:
|
193
|
+
@eof = true
|
194
|
+
return false
|
191
195
|
end
|
192
|
-
|
193
|
-
# We didn't read anything, so we must be at eof:
|
194
|
-
@eof = true
|
195
|
-
return false
|
196
196
|
end
|
197
197
|
|
198
198
|
# Consumes at most `size` bytes from the buffer.
|
@@ -205,8 +205,8 @@ module Async
|
|
205
205
|
|
206
206
|
if size == nil || size >= @read_buffer.size
|
207
207
|
# Consume the entire read buffer:
|
208
|
-
result = @read_buffer
|
209
|
-
@read_buffer.
|
208
|
+
result = @read_buffer
|
209
|
+
@read_buffer = BinaryString.new
|
210
210
|
else
|
211
211
|
# Consume only part of the read buffer:
|
212
212
|
result = @read_buffer.slice!(0, size)
|
data/lib/async/io/version.rb
CHANGED
@@ -21,6 +21,8 @@
|
|
21
21
|
require 'async/io/stream'
|
22
22
|
|
23
23
|
RSpec.describe Async::IO::Stream do
|
24
|
+
include_context Async::RSpec::Memory
|
25
|
+
|
24
26
|
let(:io) {StringIO.new}
|
25
27
|
let(:stream) {Async::IO::Stream.new(io)}
|
26
28
|
|
@@ -47,11 +49,19 @@ RSpec.describe Async::IO::Stream do
|
|
47
49
|
expect(stream.read(20)).to be == "o World"
|
48
50
|
expect(stream).to be_eof
|
49
51
|
end
|
52
|
+
|
53
|
+
context "with large content" do
|
54
|
+
let!(:io) { StringIO.new("a" * 5*1024*1024) }
|
55
|
+
|
56
|
+
it "allocates expected amount of bytes" do
|
57
|
+
expect do
|
58
|
+
stream.read(16*1024).clear until stream.eof?
|
59
|
+
end.to limit_allocations(size: 100*1024)
|
60
|
+
end
|
61
|
+
end
|
50
62
|
end
|
51
63
|
|
52
64
|
describe '#read_until' do
|
53
|
-
include_context Async::RSpec::Memory
|
54
|
-
|
55
65
|
it "can read a line" do
|
56
66
|
io.write("hello\nworld\n")
|
57
67
|
io.seek(0)
|
@@ -61,13 +71,14 @@ RSpec.describe Async::IO::Stream do
|
|
61
71
|
expect(stream.read_until("\n")).to be_nil
|
62
72
|
end
|
63
73
|
|
64
|
-
|
65
|
-
io.
|
66
|
-
io.seek(0)
|
74
|
+
context "with large content" do
|
75
|
+
let!(:io) { StringIO.new("a" * 5*1024*1024 + "b") }
|
67
76
|
|
68
|
-
|
69
|
-
|
70
|
-
|
77
|
+
it "allocates expected amount of bytes" do
|
78
|
+
expect do
|
79
|
+
stream.read_until("b").clear
|
80
|
+
end.to limit_allocations(size: 100*1024)
|
81
|
+
end
|
71
82
|
end
|
72
83
|
end
|
73
84
|
|
@@ -96,6 +107,16 @@ RSpec.describe Async::IO::Stream do
|
|
96
107
|
|
97
108
|
expect(stream.read_partial(11)).to be == "Hello World"
|
98
109
|
end
|
110
|
+
|
111
|
+
context "with large content" do
|
112
|
+
let!(:io) { StringIO.new("a" * 5*1024*1024) }
|
113
|
+
|
114
|
+
it "allocates expected amount of bytes" do
|
115
|
+
expect do
|
116
|
+
stream.read_partial(16*1024).clear until stream.eof?
|
117
|
+
end.to limit_allocations(size: 100*1024)
|
118
|
+
end
|
119
|
+
end
|
99
120
|
end
|
100
121
|
|
101
122
|
describe '#write' do
|
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.12.
|
4
|
+
version: 1.12.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1.
|
33
|
+
version: '1.7'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '1.
|
40
|
+
version: '1.7'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,6 +87,7 @@ executables: []
|
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
|
+
- ".editorconfig"
|
90
91
|
- ".gitignore"
|
91
92
|
- ".rspec"
|
92
93
|
- ".travis.yml"
|
@@ -94,6 +95,7 @@ files:
|
|
94
95
|
- README.md
|
95
96
|
- Rakefile
|
96
97
|
- async-io.gemspec
|
98
|
+
- examples/allocations.rb
|
97
99
|
- examples/chat/client.rb
|
98
100
|
- examples/chat/server.rb
|
99
101
|
- examples/issues/broken_ssl.rb
|