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 +4 -4
- data/.travis.yml +2 -0
- data/Gemfile +0 -6
- data/README.md +3 -3
- data/async-io.gemspec +1 -0
- data/examples/chat/client.rb +27 -10
- data/examples/chat/server.rb +2 -2
- data/examples/millions/client.rb +1 -1
- data/examples/millions/server.rb +1 -1
- data/lib/async/io/stream.rb +4 -1
- data/lib/async/io/version.rb +1 -1
- data/spec/async/io/c10k_spec.rb +3 -3
- data/spec/async/io/echo_spec.rb +2 -2
- data/spec/async/io/shared_endpoint/server_spec.rb +2 -2
- data/spec/async/io/stream_spec.rb +13 -0
- data/spec/spec_helper.rb +1 -19
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 316ad4a29714cbc95c2b264ba6346f7bb4dfbebdd1cb87bdfdcaef30f86e309d
|
4
|
+
data.tar.gz: 10f97c613207b25398889aacfe0e4898d7399d977f215bfea4f88d87320825aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33529f95bf9d54e4249cfa8b2f7588fc8985f336500c975e75d61a767123a164ff4369da1c34d5d0f8946ddcbbd806cd3d62b8d01021f36bbe17d48252249002
|
7
|
+
data.tar.gz: b6f84aed9ab41abef7abc0ea2a5ce0033625bfeb2fb2f6c0a5e473ec0cdf8e730730fdf6d95157a8e63c55118e471eb980a9da147a753c61a834b364ab378b01
|
data/.travis.yml
CHANGED
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
|
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
|
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
|
61
|
+
Async do
|
62
62
|
endpoint = Async::IO::Endpoint.tcp('0.0.0.0', 9000)
|
63
63
|
|
64
64
|
server = echo_server(endpoint)
|
data/async-io.gemspec
CHANGED
@@ -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
|
data/examples/chat/client.rb
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
$LOAD_PATH << File.expand_path("../../lib", __dir__)
|
4
4
|
|
5
|
-
require 'async
|
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
|
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
|
-
|
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
|
-
|
33
|
-
|
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
|
-
|
39
|
-
|
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
|
data/examples/chat/server.rb
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH << File.expand_path("../../lib", __dir__)
|
|
4
4
|
|
5
5
|
require 'set'
|
6
6
|
|
7
|
-
require 'async
|
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
|
64
|
+
Async do |task|
|
65
65
|
endpoint.accept do |peer|
|
66
66
|
stream = Async::IO::Stream.new(peer)
|
67
67
|
user = User.new(stream)
|
data/examples/millions/client.rb
CHANGED
data/examples/millions/server.rb
CHANGED
data/lib/async/io/stream.rb
CHANGED
@@ -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
|
data/lib/async/io/version.rb
CHANGED
data/spec/async/io/c10k_spec.rb
CHANGED
@@ -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
|
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
|
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
|
107
|
+
Async do |task|
|
108
108
|
responses = []
|
109
109
|
|
110
110
|
tasks = repeats.times.collect do |i|
|
data/spec/async/io/echo_spec.rb
CHANGED
@@ -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
|
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
|
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
|
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
|
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
|
data/spec/spec_helper.rb
CHANGED
@@ -1,23 +1,5 @@
|
|
1
1
|
|
2
|
-
|
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.
|
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-
|
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.
|
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.
|