async-io 1.12.2 → 1.12.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '02688119fe7ef47b527495b74b5b60d5826de683dc4bc798b63f6c61ee962049'
4
- data.tar.gz: c15e88f8b47470fe35b97ba674faaa20ac39f3cbab617a47523b66c516103125
3
+ metadata.gz: c10de5ece88f5f8366c2560647ab2cc061c12d49790cf1f3aafb6516d0fd7ad4
4
+ data.tar.gz: c970a916f8e637098bf85a842d27709cb34dae68ded5386451be3f433673d12e
5
5
  SHA512:
6
- metadata.gz: 224d6230ea743a3c4d5132222d4ef74c61362fa487c8da642ee470333be2cb8656604f5b4ccec4d28e0b799c22d13207c605ad1c4a53f2614e6cbc13c7d9ccf3
7
- data.tar.gz: a129eceb200dc5171465d6b6f902efcf37d2c6b4d722c5ae1b82c716e66e78a77c8585742950482006a89fc86fc166ec6d83ce641eea09b7ef0e2ceefd7326f9
6
+ metadata.gz: ab731c4a8ec3e2f9a3b459e62391a5294b2234ca0a62cf066f435ba33324f174f60676660924cba2ef25c8fae00fb85bb2b4556c4c96cecdbdd1bd7e9c798f35
7
+ data.tar.gz: 12c30f60cc9e1859664a79d9d6378c690d0756234410699ae79d5fbd837f014ccc10811ff4feb7ec38cda025fe300cac95051aaff5015808ec595a7107c2d426
@@ -0,0 +1,5 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = tab
5
+ indent_size = 4
@@ -7,12 +7,12 @@ before_script:
7
7
  - gem update --system
8
8
  - gem install bundler
9
9
 
10
-
11
10
  matrix:
12
11
  include:
13
12
  - rvm: 2.3
14
13
  - rvm: 2.4
15
14
  - rvm: 2.5
15
+ - rvm: 2.6
16
16
  - rvm: jruby-head
17
17
  env: JRUBY_OPTS="--debug -X+O"
18
18
  - rvm: ruby-head
@@ -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.6"
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"
@@ -22,8 +22,7 @@ class User < Async::IO::Protocol::Line
22
22
  end
23
23
 
24
24
  class Server
25
- def initialize(endpoint)
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
- @endpoint.accept do |peer|
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
- endpoint = Async::IO::Endpoint.parse(ARGV.pop || "tcp://localhost:7138")
79
- server = Server.new(endpoint)
77
+ Async.logger.level = Logger::INFO
78
+ Async.logger.info("Starting server...")
79
+ server = Server.new
80
80
 
81
- server.run
81
+ endpoint = Async::IO::Endpoint.parse(ARGV.pop || "tcp://localhost:7138")
82
+ server.run(endpoint)
@@ -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
- # Can we read directly into the buffer? (Ruby doesn't support append, only replace):
184
- if @read_buffer.empty?
185
- if @io.read(@block_size, @read_buffer)
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.dup
209
- @read_buffer.clear
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)
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Async
22
22
  module IO
23
- VERSION = "1.12.2"
23
+ VERSION = "1.12.3"
24
24
  end
25
25
  end
@@ -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
- it "minimises allocations" do
65
- io.write("hello\nworld\n")
66
- io.seek(0)
74
+ context "with large content" do
75
+ let!(:io) { StringIO.new("a" * 5*1024*1024 + "b") }
67
76
 
68
- expect do
69
- stream.read_until("\n")
70
- end.to limit_allocations(String => 3)
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.2
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-06-10 00:00:00.000000000 Z
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.6'
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.6'
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