async-io 1.18.2 → 1.18.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: 6af60edd4c664064f17db04a1146cbd88656068c1c0c95618674c6b5ce8c6943
4
- data.tar.gz: fcf301863fabc8a477bddb0854e6e25d0c4d1ba5c783322eb4d4a392c228e435
3
+ metadata.gz: 316ad4a29714cbc95c2b264ba6346f7bb4dfbebdd1cb87bdfdcaef30f86e309d
4
+ data.tar.gz: 10f97c613207b25398889aacfe0e4898d7399d977f215bfea4f88d87320825aa
5
5
  SHA512:
6
- metadata.gz: 95d4bca4d11cea4cdb29c7dbc904fae62c83a3232f6ce1d73631884bf326217c7735fe9c762092c26c1b3288226f82ab0ec4f222bd41f2863fb73282a5168769
7
- data.tar.gz: ce9921bf2cbcefb702e3af88eb61e6797726baa09f2d855f806525c153a67264abb2af53eccc9a884dc47a81af09e27ac4f6a2ccb9e92ac32d0f55244c185e9b
6
+ metadata.gz: 33529f95bf9d54e4249cfa8b2f7588fc8985f336500c975e75d61a767123a164ff4369da1c34d5d0f8946ddcbbd806cd3d62b8d01021f36bbe17d48252249002
7
+ data.tar.gz: b6f84aed9ab41abef7abc0ea2a5ce0033625bfeb2fb2f6c0a5e473ec0cdf8e730730fdf6d95157a8e63c55118e471eb980a9da147a753c61a834b364ab378b01
@@ -8,6 +8,8 @@ matrix:
8
8
  - rvm: 2.4
9
9
  - rvm: 2.5
10
10
  - rvm: 2.6
11
+ - rvm: 2.6
12
+ env: COVERAGE=PartialSummary,Coveralls
11
13
  - rvm: truffleruby
12
14
  - rvm: jruby-head
13
15
  env: JRUBY_OPTS="--debug -X+O"
data/Gemfile CHANGED
@@ -6,18 +6,12 @@ gemspec
6
6
  group :development do
7
7
  gem 'pry'
8
8
  gem 'guard-rspec'
9
- gem 'guard-yard'
10
-
11
- gem 'yard'
12
9
  end
13
10
 
14
11
  group :test do
15
12
  gem 'benchmark-ips'
16
13
  gem 'ruby-prof', platforms: :mri
17
14
 
18
- gem 'simplecov'
19
- gem 'coveralls', require: false
20
-
21
15
  gem 'async-container'
22
16
 
23
17
  gem 'http'
data/README.md CHANGED
@@ -32,7 +32,7 @@ Basic echo server (from `spec/async/io/echo_spec.rb`):
32
32
  require 'async/io'
33
33
 
34
34
  def echo_server(endpoint)
35
- Async::Reactor.run do |task|
35
+ Async do |task|
36
36
  # This is a synchronous block within the current task:
37
37
  endpoint.accept do |client|
38
38
  # This is an asynchronous block within the current reactor:
@@ -47,7 +47,7 @@ def echo_server(endpoint)
47
47
  end
48
48
 
49
49
  def echo_client(endpoint, data)
50
- Async::Reactor.run do |task|
50
+ Async do |task|
51
51
  endpoint.connect do |peer|
52
52
  result = peer.write(data)
53
53
 
@@ -58,7 +58,7 @@ def echo_client(endpoint, data)
58
58
  end
59
59
  end
60
60
 
61
- Async::Reactor.run do
61
+ Async do
62
62
  endpoint = Async::IO::Endpoint.tcp('0.0.0.0', 9000)
63
63
 
64
64
  server = echo_server(endpoint)
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.required_ruby_version = '~> 2.3'
22
22
 
23
23
  spec.add_development_dependency "bundler"
24
+ spec.add_development_dependency "covered"
24
25
  spec.add_development_dependency "rake", "~> 10.0"
25
26
  spec.add_development_dependency "rspec", "~> 3.0"
26
27
  end
@@ -2,7 +2,8 @@
2
2
 
3
3
  $LOAD_PATH << File.expand_path("../../lib", __dir__)
4
4
 
5
- require 'async/reactor'
5
+ require 'async'
6
+ require 'async/notification'
6
7
  require 'async/io/stream'
7
8
  require 'async/io/host_endpoint'
8
9
  require 'async/io/protocol/line'
@@ -18,23 +19,39 @@ input = Async::IO::Protocol::Line.new(
18
19
  )
19
20
  )
20
21
 
21
- Async::Reactor.run do |task|
22
+ Async do |task|
22
23
  socket = endpoint.connect
23
24
  stream = Async::IO::Stream.new(socket)
24
25
  user = User.new(stream)
25
26
 
26
- connection = task.async do
27
+ # This is used to track whether either reading from stdin failed or reading from network failed.
28
+ finished = Async::Notification.new
29
+
30
+ # Read lines from stdin and write to network.
31
+ terminal = task.async do
32
+ while line = input.read_line
33
+ user.write_lines line
34
+ end
35
+ rescue EOFError
36
+ # It's okay, we are disconnecting, because stdin has closed.
37
+ ensure
38
+ finished.signal
39
+ end
40
+
41
+ # Read lines from network and write to stdout.
42
+ network = task.async do
27
43
  while line = user.read_line
28
44
  puts line
29
45
  end
46
+ ensure
47
+ finished.signal
30
48
  end
31
49
 
32
- while line = input.read_line
33
- user.write_lines line
34
- end
35
- rescue EOFError
36
- # It's okay, we are disconnecting, because stdin has closed.
50
+ # Wait for any of the above processes to finish:
51
+ finished.wait
37
52
  ensure
38
- connection.stop
39
- user.close
53
+ # Stop all the nested tasks if we are exiting:
54
+ network.stop if network
55
+ terminal.stop if terminal
56
+ user.close if user
40
57
  end
@@ -4,7 +4,7 @@ $LOAD_PATH << File.expand_path("../../lib", __dir__)
4
4
 
5
5
  require 'set'
6
6
 
7
- require 'async/reactor'
7
+ require 'async'
8
8
  require 'async/io/host_endpoint'
9
9
  require 'async/io/protocol/line'
10
10
 
@@ -61,7 +61,7 @@ class Server
61
61
  end
62
62
 
63
63
  def run(endpoint)
64
- Async::Reactor.run do |task|
64
+ Async do |task|
65
65
  endpoint.accept do |peer|
66
66
  stream = Async::IO::Stream.new(peer)
67
67
  user = User.new(stream)
@@ -21,7 +21,7 @@ puts "Total number of connections: #{CONCURRENCY * TASKS * REPEATS}!"
21
21
 
22
22
  begin
23
23
  container = Async::Container::Forked.new(concurrency: CONCURRENCY) do
24
- Async::Reactor.run do |task|
24
+ Async do |task|
25
25
  connections = []
26
26
 
27
27
  TASKS.times do
@@ -14,7 +14,7 @@ class Server
14
14
  end
15
15
 
16
16
  def run(endpoint)
17
- Async::Reactor.run do |task|
17
+ Async do |task|
18
18
  task.async do |subtask|
19
19
  while true
20
20
  subtask.sleep 10
@@ -85,8 +85,11 @@ module Async
85
85
  # @param pattern [String] The pattern to match.
86
86
  # @return [String] The contents of the stream up until the pattern, which is consumed but not returned.
87
87
  def read_until(pattern, offset = 0, chomp: true)
88
+ # We don't want to split on the pattern, so we subtract the size of the pattern.
89
+ split_offset = pattern.bytesize - 1
90
+
88
91
  until index = @read_buffer.index(pattern, offset)
89
- offset = @read_buffer.size
92
+ offset = [0, @read_buffer.size - split_offset].max
90
93
 
91
94
  return unless fill_read_buffer
92
95
  end
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Async
22
22
  module IO
23
- VERSION = "1.18.2"
23
+ VERSION = "1.18.3"
24
24
  end
25
25
  end
@@ -31,7 +31,7 @@ RSpec.describe "echo client/server" do
31
31
  let(:server_address) {Async::IO::Address.tcp('0.0.0.0', 10102)}
32
32
 
33
33
  def echo_server(server_address)
34
- Async::Reactor.run do |task|
34
+ Async do |task|
35
35
  connection_count = 0
36
36
 
37
37
  connections_complete = task.async do
@@ -66,7 +66,7 @@ RSpec.describe "echo client/server" do
66
66
  end
67
67
 
68
68
  def echo_client(server_address, data, responses)
69
- Async::Reactor.run do |task|
69
+ Async do |task|
70
70
  begin
71
71
  Async::IO::Socket.connect(server_address) do |peer|
72
72
  result = peer.write(data)
@@ -104,7 +104,7 @@ RSpec.describe "echo client/server" do
104
104
 
105
105
  it "should send/receive 10,000 messages" do
106
106
  fork_server do
107
- Async::Reactor.run do |task|
107
+ Async do |task|
108
108
  responses = []
109
109
 
110
110
  tasks = repeats.times.collect do |i|
@@ -26,7 +26,7 @@ RSpec.describe "echo client/server" do
26
26
  let(:server_address) {Async::IO::Address.tcp('0.0.0.0', 9002)}
27
27
 
28
28
  def echo_server(server_address)
29
- Async::Reactor.run do |task|
29
+ Async do |task|
30
30
  # This is a synchronous block within the current task:
31
31
  Async::IO::Socket.accept(server_address) do |client|
32
32
  # This is an asynchronous block within the current reactor:
@@ -41,7 +41,7 @@ RSpec.describe "echo client/server" do
41
41
  end
42
42
 
43
43
  def echo_client(server_address, data, responses)
44
- Async::Reactor.run do |task|
44
+ Async do |task|
45
45
  Async::IO::Socket.connect(server_address) do |peer|
46
46
  result = peer.write(data)
47
47
 
@@ -36,7 +36,7 @@ RSpec.shared_examples_for Async::IO::SharedEndpoint do |container_class|
36
36
  let(:client_endpoint) {Async::IO::SSLEndpoint.new(endpoint, ssl_context: client_context)}
37
37
 
38
38
  let!(:bound_endpoint) do
39
- Async::Reactor.run do
39
+ Async do
40
40
  Async::IO::SharedEndpoint.bound(server_endpoint)
41
41
  end.wait
42
42
  end
@@ -49,7 +49,7 @@ RSpec.shared_examples_for Async::IO::SharedEndpoint do |container_class|
49
49
  end
50
50
  end
51
51
 
52
- Async::Reactor.run do
52
+ Async do
53
53
  client_endpoint.connect do |peer|
54
54
  expect(peer.read(11)).to eq "Hello World"
55
55
  end
@@ -82,6 +82,19 @@ RSpec.describe Async::IO::Stream do
82
82
  expect(stream.read_until("\n")).to be_nil
83
83
  end
84
84
 
85
+ context "with 1-byte block size" do
86
+ let!(:stream) {Async::IO::Stream.new(buffer, block_size: 1)}
87
+
88
+ it "can read a line with a multi-byte pattern" do
89
+ io.write("hello\r\nworld\r\n")
90
+ io.seek(0)
91
+
92
+ expect(stream.read_until("\r\n")).to be == 'hello'
93
+ expect(stream.read_until("\r\n")).to be == 'world'
94
+ expect(stream.read_until("\r\n")).to be_nil
95
+ end
96
+ end
97
+
85
98
  context "with large content" do
86
99
  it "allocates expected amount of bytes" do
87
100
  expect do
@@ -1,23 +1,5 @@
1
1
 
2
- if ENV['COVERAGE'] || ENV['TRAVIS']
3
- begin
4
- require 'simplecov'
5
-
6
- SimpleCov.start do
7
- add_filter "/spec/"
8
- end
9
-
10
- if ENV['TRAVIS']
11
- require 'coveralls'
12
- Coveralls.wear!
13
- end
14
- rescue LoadError
15
- warn "Could not load simplecov: #{$!}"
16
- end
17
- end
18
-
19
- require "bundler/setup"
20
- require "async/io"
2
+ require 'covered/rspec'
21
3
 
22
4
  if RUBY_ENGINE == "truffleruby"
23
5
  warn "Workarounds for TruffleRuby enabled..."
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.18.2
4
+ version: 1.18.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: 2019-01-21 00:00:00.000000000 Z
11
+ date: 2019-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: covered
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -171,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
185
  - !ruby/object:Gem::Version
172
186
  version: '0'
173
187
  requirements: []
174
- rubygems_version: 3.0.1
188
+ rubygems_version: 3.0.2
175
189
  signing_key:
176
190
  specification_version: 4
177
191
  summary: Provides support for asynchonous TCP, UDP, UNIX and SSL sockets.