async-io 1.28.0 → 1.31.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/async/io/host_endpoint.rb +1 -1
- data/lib/async/io/peer.rb +2 -2
- data/lib/async/io/socket.rb +2 -2
- data/lib/async/io/ssl_socket.rb +2 -4
- data/lib/async/io/stream.rb +2 -2
- data/lib/async/io/tcp_socket.rb +1 -1
- data/{spec/async/io/socket/udp_spec.rb → lib/async/io/threads.rb} +56 -36
- data/lib/async/io/trap.rb +8 -3
- data/lib/async/io/version.rb +1 -1
- metadata +45 -94
- data/.editorconfig +0 -6
- data/.gitignore +0 -13
- data/.rspec +0 -3
- data/.travis.yml +0 -26
- data/.yardopts +0 -2
- data/Gemfile +0 -13
- data/README.md +0 -171
- data/async-io.gemspec +0 -30
- data/examples/allocations/byteslice.rb +0 -29
- data/examples/allocations/memory.rb +0 -16
- data/examples/allocations/read_chunks.rb +0 -18
- data/examples/chat/client.rb +0 -58
- data/examples/chat/server.rb +0 -83
- data/examples/defer/worker.rb +0 -29
- data/examples/echo/client.rb +0 -23
- data/examples/echo/server.rb +0 -58
- data/examples/issues/broken_ssl.rb +0 -15
- data/examples/issues/pipes.rb +0 -34
- data/examples/millions/client.rb +0 -44
- data/examples/millions/server.rb +0 -41
- data/examples/udp/client.rb +0 -14
- data/examples/udp/server.rb +0 -16
- data/gems/nio4r-2.3.gemfile +0 -3
- data/spec/addrinfo.rb +0 -16
- data/spec/async/io/buffer_spec.rb +0 -48
- data/spec/async/io/c10k_spec.rb +0 -138
- data/spec/async/io/echo_spec.rb +0 -75
- data/spec/async/io/endpoint_spec.rb +0 -105
- data/spec/async/io/generic_examples.rb +0 -73
- data/spec/async/io/generic_spec.rb +0 -107
- data/spec/async/io/notification_spec.rb +0 -46
- data/spec/async/io/protocol/line_spec.rb +0 -81
- data/spec/async/io/shared_endpoint/server_spec.rb +0 -72
- data/spec/async/io/shared_endpoint_spec.rb +0 -65
- data/spec/async/io/socket/tcp_spec.rb +0 -101
- data/spec/async/io/socket_spec.rb +0 -149
- data/spec/async/io/ssl_server_spec.rb +0 -133
- data/spec/async/io/ssl_socket_spec.rb +0 -96
- data/spec/async/io/standard_spec.rb +0 -47
- data/spec/async/io/stream_context.rb +0 -30
- data/spec/async/io/stream_spec.rb +0 -337
- data/spec/async/io/tcp_socket_spec.rb +0 -84
- data/spec/async/io/trap_spec.rb +0 -52
- data/spec/async/io/udp_socket_spec.rb +0 -56
- data/spec/async/io/unix_endpoint_spec.rb +0 -106
- data/spec/async/io/unix_socket_spec.rb +0 -66
- data/spec/async/io/wrap/http_rb_spec.rb +0 -47
- data/spec/async/io/wrap/tcp_spec.rb +0 -79
- data/spec/spec_helper.rb +0 -15
@@ -1,84 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the "Software"), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, reactor to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in
|
13
|
-
# all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
# THE SOFTWARE.
|
22
|
-
|
23
|
-
require 'async/io/tcp_socket'
|
24
|
-
|
25
|
-
require_relative 'generic_examples'
|
26
|
-
|
27
|
-
RSpec.describe Async::IO::TCPSocket, timeout: 1 do
|
28
|
-
include_context Async::RSpec::Reactor
|
29
|
-
|
30
|
-
it_should_behave_like Async::IO::Generic
|
31
|
-
|
32
|
-
# Shared port for localhost network tests.
|
33
|
-
let(:server_address) {Async::IO::Address.tcp("localhost", 6788)}
|
34
|
-
let(:data) {"The quick brown fox jumped over the lazy dog."}
|
35
|
-
|
36
|
-
describe Async::IO::TCPServer do
|
37
|
-
it_should_behave_like Async::IO::Generic
|
38
|
-
end
|
39
|
-
|
40
|
-
describe Async::IO::TCPServer do
|
41
|
-
let!(:server_task) do
|
42
|
-
reactor.async do |task|
|
43
|
-
server = Async::IO::TCPServer.new("localhost", 6788)
|
44
|
-
|
45
|
-
peer, address = server.accept
|
46
|
-
|
47
|
-
data = peer.gets
|
48
|
-
peer.puts(data)
|
49
|
-
peer.flush
|
50
|
-
|
51
|
-
peer.close
|
52
|
-
server.close
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
let(:client) {Async::IO::TCPSocket.new("localhost", 6788)}
|
57
|
-
|
58
|
-
it "can read into output buffer" do
|
59
|
-
client.puts("Hello World")
|
60
|
-
client.flush
|
61
|
-
|
62
|
-
buffer = String.new
|
63
|
-
# 20 is bigger than echo response...
|
64
|
-
data = client.read(20, buffer)
|
65
|
-
|
66
|
-
expect(buffer).to_not be_empty
|
67
|
-
expect(buffer).to be == data
|
68
|
-
|
69
|
-
client.close
|
70
|
-
server_task.wait
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should start server and send data" do
|
74
|
-
# Accept a single incoming connection and then finish.
|
75
|
-
client.puts(data)
|
76
|
-
client.flush
|
77
|
-
|
78
|
-
expect(client.gets).to be == data
|
79
|
-
|
80
|
-
client.close
|
81
|
-
server_task.wait
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
data/spec/async/io/trap_spec.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the "Software"), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in
|
13
|
-
# all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
# THE SOFTWARE.
|
22
|
-
|
23
|
-
require 'async/io/trap'
|
24
|
-
|
25
|
-
RSpec.describe Async::IO::Trap do
|
26
|
-
include_context Async::RSpec::Reactor
|
27
|
-
|
28
|
-
subject {described_class.new(:USR2)}
|
29
|
-
|
30
|
-
it "can ignore signal" do
|
31
|
-
subject.ignore!
|
32
|
-
|
33
|
-
Process.kill(:USR2, Process.pid)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should wait for signal" do
|
37
|
-
trapped = false
|
38
|
-
|
39
|
-
waiting_task = reactor.async do
|
40
|
-
subject.wait do
|
41
|
-
trapped = true
|
42
|
-
break
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
subject.trigger
|
47
|
-
|
48
|
-
waiting_task.wait
|
49
|
-
|
50
|
-
expect(trapped).to be_truthy
|
51
|
-
end
|
52
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the "Software"), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in
|
13
|
-
# all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
# THE SOFTWARE.
|
22
|
-
|
23
|
-
require 'async/io/udp_socket'
|
24
|
-
|
25
|
-
require_relative 'generic_examples'
|
26
|
-
|
27
|
-
RSpec.describe Async::IO::UDPSocket do
|
28
|
-
include_context Async::RSpec::Reactor
|
29
|
-
|
30
|
-
it_should_behave_like Async::IO::Generic
|
31
|
-
|
32
|
-
let(:data) {"The quick brown fox jumped over the lazy dog."}
|
33
|
-
|
34
|
-
it "should echo data back to peer" do
|
35
|
-
reactor.async do
|
36
|
-
server = Async::IO::UDPSocket.new(Socket::AF_INET)
|
37
|
-
server.bind("127.0.0.1", 6778)
|
38
|
-
|
39
|
-
packet, address = server.recvfrom(512)
|
40
|
-
server.send(packet, 0, address[3], address[1])
|
41
|
-
|
42
|
-
server.close
|
43
|
-
end
|
44
|
-
|
45
|
-
reactor.async do
|
46
|
-
client = Async::IO::UDPSocket.new(Socket::AF_INET)
|
47
|
-
client.connect("127.0.0.1", 6778)
|
48
|
-
|
49
|
-
client.send(data, 0)
|
50
|
-
response = client.recv(512)
|
51
|
-
client.close
|
52
|
-
|
53
|
-
expect(response).to be == data
|
54
|
-
end.wait
|
55
|
-
end
|
56
|
-
end
|
@@ -1,106 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the "Software"), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in
|
13
|
-
# all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
# THE SOFTWARE.
|
22
|
-
|
23
|
-
require 'async/io/unix_endpoint'
|
24
|
-
require 'async/io/stream'
|
25
|
-
|
26
|
-
RSpec.describe Async::IO::UNIXEndpoint do
|
27
|
-
include_context Async::RSpec::Reactor
|
28
|
-
|
29
|
-
let(:data) {"The quick brown fox jumped over the lazy dog."}
|
30
|
-
let(:path) {File.join(__dir__, "unix-socket")}
|
31
|
-
subject {described_class.unix(path)}
|
32
|
-
|
33
|
-
before(:each) do
|
34
|
-
FileUtils.rm_f path
|
35
|
-
end
|
36
|
-
|
37
|
-
after do
|
38
|
-
FileUtils.rm_f path
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should echo data back to peer" do
|
42
|
-
server_task = reactor.async do
|
43
|
-
subject.accept do |peer|
|
44
|
-
peer.send(peer.recv(512))
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
reactor.async do
|
49
|
-
subject.connect do |client|
|
50
|
-
client.send(data)
|
51
|
-
|
52
|
-
response = client.recv(512)
|
53
|
-
|
54
|
-
expect(response).to be == data
|
55
|
-
end
|
56
|
-
end.wait
|
57
|
-
|
58
|
-
server_task.stop
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should fails to bind if there is an existing binding" do
|
62
|
-
condition = Async::Condition.new
|
63
|
-
|
64
|
-
reactor.async do
|
65
|
-
condition.wait
|
66
|
-
|
67
|
-
expect do
|
68
|
-
subject.bind
|
69
|
-
end.to raise_error(Errno::EADDRINUSE)
|
70
|
-
end
|
71
|
-
|
72
|
-
server_task = reactor.async do
|
73
|
-
subject.bind do |server|
|
74
|
-
server.listen(1)
|
75
|
-
condition.signal
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
server_task.stop
|
80
|
-
end
|
81
|
-
|
82
|
-
context "using buffered stream" do
|
83
|
-
it "can use stream to read and write data" do
|
84
|
-
server_task = reactor.async do |task|
|
85
|
-
subject.accept do |peer|
|
86
|
-
stream = Async::IO::Stream.new(peer)
|
87
|
-
stream.write(stream.read)
|
88
|
-
stream.close
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
reactor.async do
|
93
|
-
subject.connect do |client|
|
94
|
-
stream = Async::IO::Stream.new(client)
|
95
|
-
|
96
|
-
stream.write(data)
|
97
|
-
stream.close_write
|
98
|
-
|
99
|
-
expect(stream.read).to be == data
|
100
|
-
end
|
101
|
-
end.wait
|
102
|
-
|
103
|
-
server_task.stop
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the "Software"), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in
|
13
|
-
# all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
# THE SOFTWARE.
|
22
|
-
|
23
|
-
require 'async/io/unix_socket'
|
24
|
-
|
25
|
-
require_relative 'generic_examples'
|
26
|
-
|
27
|
-
RSpec.describe Async::IO::UNIXSocket do
|
28
|
-
include_context Async::RSpec::Reactor
|
29
|
-
|
30
|
-
it_should_behave_like Async::IO::Generic
|
31
|
-
|
32
|
-
let(:path) {File.join(__dir__, "unix-socket")}
|
33
|
-
let(:data) {"The quick brown fox jumped over the lazy dog."}
|
34
|
-
|
35
|
-
before(:each) do
|
36
|
-
FileUtils.rm_f path
|
37
|
-
end
|
38
|
-
|
39
|
-
after do
|
40
|
-
FileUtils.rm_f path
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should echo data back to peer" do
|
44
|
-
reactor.async do
|
45
|
-
Async::IO::UNIXServer.wrap(path) do |server|
|
46
|
-
server.accept do |peer|
|
47
|
-
peer.send(peer.recv(512))
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
reactor.async do
|
53
|
-
Async::IO::UNIXSocket.wrap(path) do |client|
|
54
|
-
client.send(data)
|
55
|
-
|
56
|
-
response = client.recv(512)
|
57
|
-
|
58
|
-
expect(response).to be == data
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
RSpec.describe Async::IO::UNIXServer do
|
65
|
-
it_should_behave_like Async::IO::Generic
|
66
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright, 2018, by Thibaut Girka.
|
4
|
-
# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
5
|
-
#
|
6
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
-
# of this software and associated documentation files (the "Software"), to deal
|
8
|
-
# in the Software without restriction, including without limitation the rights
|
9
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
-
# copies of the Software, and to permit persons to whom the Software is
|
11
|
-
# furnished to do so, subject to the following conditions:
|
12
|
-
#
|
13
|
-
# The above copyright notice and this permission notice shall be included in
|
14
|
-
# all copies or substantial portions of the Software.
|
15
|
-
#
|
16
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
-
# THE SOFTWARE.
|
23
|
-
|
24
|
-
require 'http'
|
25
|
-
require 'openssl'
|
26
|
-
|
27
|
-
require 'async/io/tcp_socket'
|
28
|
-
require 'async/io/ssl_socket'
|
29
|
-
|
30
|
-
RSpec.describe Async::IO do
|
31
|
-
let(:wrappers) do
|
32
|
-
{socket_class: Async::IO::TCPSocket, ssl_socket_class: Async::IO::SSLSocket}
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "inside reactor" do
|
36
|
-
include_context Async::RSpec::Reactor
|
37
|
-
|
38
|
-
it "should fetch page" do
|
39
|
-
expect(Async::IO::SSLSocket).to receive(:new).and_call_original
|
40
|
-
|
41
|
-
expect do
|
42
|
-
response = HTTP.get('https://www.google.com', wrappers)
|
43
|
-
response.connection.close
|
44
|
-
end.to_not raise_exception
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the "Software"), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in
|
13
|
-
# all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
# THE SOFTWARE.
|
22
|
-
|
23
|
-
require 'net/http'
|
24
|
-
|
25
|
-
require 'async/io/tcp_socket'
|
26
|
-
|
27
|
-
# There are different ways to achieve this. This is really just a proof of concept.
|
28
|
-
module Wrap
|
29
|
-
module TCPServer
|
30
|
-
def self.new(*args)
|
31
|
-
if Async::Task.current?
|
32
|
-
Async::IO::TCPServer.new(*args)
|
33
|
-
else
|
34
|
-
::TCPServer.new(*args)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
module TCPSocket
|
40
|
-
def self.new(*args)
|
41
|
-
if Async::Task.current?
|
42
|
-
Async::IO::TCPSocket.new(*args)
|
43
|
-
else
|
44
|
-
::TCPSocket.new(*args)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.open(*args)
|
49
|
-
self.new(*args)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# TruffleRuby uses Socket.tcp in Net::HTTP.get_response, not TCPSocket.open
|
55
|
-
RSpec.describe Async::IO::TCPSocket, if: RUBY_ENGINE != "truffleruby" do
|
56
|
-
describe "inside reactor" do
|
57
|
-
include_context Async::RSpec::Reactor
|
58
|
-
|
59
|
-
before(:all) do
|
60
|
-
Net::HTTP.include(Wrap)
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should fetch page" do
|
64
|
-
expect(Async::IO::TCPSocket).to receive(:new).and_call_original
|
65
|
-
|
66
|
-
expect do
|
67
|
-
Net::HTTP.get_response('www.google.com', '/')
|
68
|
-
end.to_not raise_exception
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
describe "outside reactor" do
|
73
|
-
it "should fetch page" do
|
74
|
-
expect do
|
75
|
-
Net::HTTP.get_response('www.google.com', '/')
|
76
|
-
end.to_not raise_exception
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|