async-io 1.27.6 → 1.30.1
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/stream.rb +16 -42
- data/{spec/async/io/trap_spec.rb → lib/async/io/threads.rb} +37 -26
- data/lib/async/io/trap.rb +8 -3
- data/lib/async/io/version.rb +1 -1
- metadata +50 -99
- data/.editorconfig +0 -6
- data/.gitignore +0 -13
- data/.rspec +0 -3
- data/.travis.yml +0 -25
- data/.yardopts +0 -2
- data/Gemfile +0 -20
- 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 -67
- data/spec/async/io/socket/tcp_spec.rb +0 -101
- data/spec/async/io/socket/udp_spec.rb +0 -65
- 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/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,72 +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/ssl_socket'
|
24
|
-
require 'async/rspec/ssl'
|
25
|
-
|
26
|
-
require 'async/io/host_endpoint'
|
27
|
-
require 'async/io/shared_endpoint'
|
28
|
-
|
29
|
-
require 'async/container'
|
30
|
-
|
31
|
-
RSpec.shared_examples_for Async::IO::SharedEndpoint do |container_class|
|
32
|
-
include_context Async::RSpec::SSL::VerifiedContexts
|
33
|
-
include_context Async::RSpec::SSL::ValidCertificate
|
34
|
-
|
35
|
-
let(:endpoint) {Async::IO::Endpoint.tcp("127.0.0.1", 6781, reuse_port: true)}
|
36
|
-
let(:server_endpoint) {Async::IO::SSLEndpoint.new(endpoint, ssl_context: server_context)}
|
37
|
-
let(:client_endpoint) {Async::IO::SSLEndpoint.new(endpoint, ssl_context: client_context)}
|
38
|
-
|
39
|
-
let!(:bound_endpoint) do
|
40
|
-
Async do
|
41
|
-
Async::IO::SharedEndpoint.bound(server_endpoint)
|
42
|
-
end.wait
|
43
|
-
end
|
44
|
-
|
45
|
-
let(:container) {container_class.new}
|
46
|
-
|
47
|
-
it "can use bound endpoint in container" do
|
48
|
-
container.async do
|
49
|
-
bound_endpoint.accept do |peer|
|
50
|
-
peer.write "Hello World"
|
51
|
-
peer.close
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
Async do
|
56
|
-
client_endpoint.connect do |peer|
|
57
|
-
expect(peer.read(11)).to eq "Hello World"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
container.stop
|
62
|
-
bound_endpoint.close
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
RSpec.describe Async::Container::Forked, if: Process.respond_to?(:fork) do
|
67
|
-
it_behaves_like Async::IO::SharedEndpoint, described_class
|
68
|
-
end
|
69
|
-
|
70
|
-
RSpec.describe Async::Container::Threaded, if: RUBY_PLATFORM !~ /darwin/ do
|
71
|
-
it_behaves_like Async::IO::SharedEndpoint, described_class
|
72
|
-
end
|
@@ -1,67 +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/host_endpoint'
|
24
|
-
require 'async/io/shared_endpoint'
|
25
|
-
|
26
|
-
require 'pry'
|
27
|
-
|
28
|
-
RSpec.describe Async::IO::SharedEndpoint do
|
29
|
-
include_context Async::RSpec::Reactor
|
30
|
-
|
31
|
-
describe '#bound' do
|
32
|
-
let(:endpoint) {Async::IO::Endpoint.tcp("localhost", 5123, timeout: 10)}
|
33
|
-
|
34
|
-
it "can bind to shared endpoint" do
|
35
|
-
bound_endpoint = described_class.bound(endpoint)
|
36
|
-
expect(bound_endpoint.wrappers).to_not be_empty
|
37
|
-
|
38
|
-
wrapper = bound_endpoint.wrappers.first
|
39
|
-
expect(wrapper).to be_a Async::IO::Socket
|
40
|
-
expect(wrapper.timeout).to be == endpoint.timeout
|
41
|
-
|
42
|
-
bound_endpoint.close
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe '#connected' do
|
47
|
-
let(:endpoint) {Async::IO::Endpoint.tcp("localhost", 5124, timeout: 10)}
|
48
|
-
|
49
|
-
it "can connect to shared endpoint" do
|
50
|
-
server_task = reactor.async do
|
51
|
-
endpoint.accept do |io|
|
52
|
-
io.close
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
connected_endpoint = described_class.connected(endpoint)
|
57
|
-
expect(connected_endpoint.wrappers).to_not be_empty
|
58
|
-
|
59
|
-
wrapper = connected_endpoint.wrappers.first
|
60
|
-
expect(wrapper).to be_a Async::IO::Socket
|
61
|
-
expect(wrapper.timeout).to be == endpoint.timeout
|
62
|
-
|
63
|
-
connected_endpoint.close
|
64
|
-
server_task.stop
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,101 +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/tcp_socket'
|
24
|
-
|
25
|
-
RSpec.describe Async::IO::Socket do
|
26
|
-
include_context Async::RSpec::Reactor
|
27
|
-
|
28
|
-
# Shared port for localhost network tests.
|
29
|
-
let(:server_address) {Async::IO::Address.tcp("127.0.0.1", 6788)}
|
30
|
-
let(:local_address) {Async::IO::Address.tcp("127.0.0.1", 0)}
|
31
|
-
let(:data) {"The quick brown fox jumped over the lazy dog."}
|
32
|
-
|
33
|
-
let!(:server_task) do
|
34
|
-
# Accept a single incoming connection and then finish.
|
35
|
-
reactor.async do |task|
|
36
|
-
Async::IO::Socket.bind(server_address) do |server|
|
37
|
-
server.listen(10)
|
38
|
-
|
39
|
-
server.accept do |peer, address|
|
40
|
-
data = peer.read(512)
|
41
|
-
peer.write(data)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe 'basic tcp server' do
|
48
|
-
it "should start server and send data" do
|
49
|
-
reactor.async do
|
50
|
-
Async::IO::Socket.connect(server_address) do |client|
|
51
|
-
client.write(data)
|
52
|
-
client.close_write
|
53
|
-
|
54
|
-
expect(client.read(512)).to be == data
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe 'non-blocking tcp connect' do
|
61
|
-
it "can specify local address" do
|
62
|
-
reactor.async do |task|
|
63
|
-
Async::IO::Socket.connect(server_address, local_address: local_address) do |client|
|
64
|
-
client.write(data)
|
65
|
-
client.close_write
|
66
|
-
|
67
|
-
expect(client.read(512)).to be == data
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should start server and send data" do
|
73
|
-
reactor.async do |task|
|
74
|
-
Async::IO::Socket.connect(server_address) do |client|
|
75
|
-
client.write(data)
|
76
|
-
client.close_write
|
77
|
-
|
78
|
-
expect(client.read(512)).to be == data
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
it "can connect socket and read/write in a different task" do
|
84
|
-
reactor.async do |task|
|
85
|
-
socket = Async::IO::Socket.connect(server_address)
|
86
|
-
|
87
|
-
expect(socket).to_not be_nil
|
88
|
-
expect(socket).to be_kind_of Async::Wrapper
|
89
|
-
|
90
|
-
reactor.async do
|
91
|
-
socket.write(data)
|
92
|
-
socket.close_write
|
93
|
-
|
94
|
-
expect(socket.read(512)).to be == data
|
95
|
-
|
96
|
-
socket.close
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
@@ -1,65 +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
|
-
RSpec.describe Async::IO::Socket do
|
26
|
-
include_context Async::RSpec::Reactor
|
27
|
-
|
28
|
-
# Shared port for localhost network tests.
|
29
|
-
let(:server_address) {Async::IO::Address.udp("127.0.0.1", 6778)}
|
30
|
-
let(:data) {"The quick brown fox jumped over the lazy dog."}
|
31
|
-
|
32
|
-
let!(:server_task) do
|
33
|
-
reactor.async do
|
34
|
-
Async::IO::Socket.bind(server_address) do |server|
|
35
|
-
packet, address = server.recvfrom(512)
|
36
|
-
|
37
|
-
server.send(packet, 0, address)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe 'basic udp server' do
|
43
|
-
it "should echo data back to peer" do
|
44
|
-
reactor.async do
|
45
|
-
Async::IO::Socket.connect(server_address) do |client|
|
46
|
-
client.send(data)
|
47
|
-
response = client.recv(512)
|
48
|
-
|
49
|
-
expect(response).to be == data
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should use unconnected socket" do
|
55
|
-
reactor.async do
|
56
|
-
Async::IO::UDPSocket.wrap(server_address.afamily) do |client|
|
57
|
-
client.send(data, 0, server_address)
|
58
|
-
response, address = client.recvfrom(512)
|
59
|
-
|
60
|
-
expect(response).to be == data
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,149 +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/socket'
|
24
|
-
require 'async/io/address'
|
25
|
-
|
26
|
-
require_relative 'generic_examples'
|
27
|
-
|
28
|
-
RSpec.describe Async::IO::BasicSocket do
|
29
|
-
it_should_behave_like Async::IO::Generic
|
30
|
-
end
|
31
|
-
|
32
|
-
RSpec.describe Async::IO::Socket do
|
33
|
-
include_context Async::RSpec::Reactor
|
34
|
-
|
35
|
-
it_should_behave_like Async::IO::Generic
|
36
|
-
|
37
|
-
describe '#connect' do
|
38
|
-
let(:address) {Async::IO::Address.tcp('127.0.0.1', 12345)}
|
39
|
-
|
40
|
-
it "should fail to connect if no listening server" do
|
41
|
-
expect do
|
42
|
-
Async::IO::Socket.connect(address)
|
43
|
-
end.to raise_exception(Errno::ECONNREFUSED)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should close the socket when interrupted by a timeout" do
|
47
|
-
wrapper = double()
|
48
|
-
expect(Async::IO::Socket).to receive(:build).and_return(wrapper)
|
49
|
-
expect(wrapper).to receive(:connect).and_raise Async::TimeoutError
|
50
|
-
expect(wrapper).to receive(:close)
|
51
|
-
expect do
|
52
|
-
Async::IO::Socket.connect(address)
|
53
|
-
end.to raise_exception(Async::TimeoutError)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe '#bind' do
|
58
|
-
it "should fail to bind to port < 1024" do
|
59
|
-
address = Async::IO::Address.tcp('127.0.0.1', 1)
|
60
|
-
|
61
|
-
expect do
|
62
|
-
Async::IO::Socket.bind(address)
|
63
|
-
end.to raise_exception(Errno::EACCES)
|
64
|
-
end
|
65
|
-
|
66
|
-
it "can bind to port 0" do
|
67
|
-
address = Async::IO::Address.tcp('127.0.0.1', 0)
|
68
|
-
|
69
|
-
Async::IO::Socket.bind(address) do |socket|
|
70
|
-
expect(socket.local_address.ip_port).to be > 10000
|
71
|
-
|
72
|
-
expect(Async::Task.current.annotation).to include("#{socket.local_address.ip_port}")
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe '#sync' do
|
78
|
-
it "should set TCP_NODELAY" do
|
79
|
-
address = Async::IO::Address.tcp('127.0.0.1', 0)
|
80
|
-
|
81
|
-
socket = Async::IO::Socket.wrap(::Socket::AF_INET, ::Socket::SOCK_STREAM, ::Socket::IPPROTO_TCP)
|
82
|
-
|
83
|
-
socket.sync = true
|
84
|
-
expect(socket.getsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY).bool).to be true
|
85
|
-
|
86
|
-
socket.close
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
describe '#timeout' do
|
91
|
-
subject{described_class.pair(:UNIX, :STREAM, 0)}
|
92
|
-
|
93
|
-
it "should timeout while waiting to receive data" do
|
94
|
-
s1, s2 = *subject
|
95
|
-
|
96
|
-
s2.timeout = 1
|
97
|
-
|
98
|
-
expect{s2.recv(32)}.to raise_exception(Async::TimeoutError, "execution expired")
|
99
|
-
|
100
|
-
s1.close
|
101
|
-
s2.close
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
describe '.pair' do
|
106
|
-
subject{described_class.pair(:UNIX, :STREAM, 0)}
|
107
|
-
|
108
|
-
it "should be able to send and recv" do
|
109
|
-
s1, s2 = *subject
|
110
|
-
|
111
|
-
s1.send "Hello World", 0
|
112
|
-
s1.close
|
113
|
-
|
114
|
-
expect(s2.recv(32)).to be == "Hello World"
|
115
|
-
s2.close
|
116
|
-
end
|
117
|
-
|
118
|
-
it "should be connected" do
|
119
|
-
s1, s2 = *subject
|
120
|
-
|
121
|
-
expect(s1).to be_connected
|
122
|
-
|
123
|
-
s1.close
|
124
|
-
|
125
|
-
expect(s2).to_not be_connected
|
126
|
-
|
127
|
-
s2.close
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
context '.pipe' do
|
132
|
-
let(:sockets) do
|
133
|
-
@sockets = described_class.pair(Socket::AF_UNIX, Socket::SOCK_STREAM)
|
134
|
-
end
|
135
|
-
|
136
|
-
after do
|
137
|
-
@sockets&.each(&:close)
|
138
|
-
end
|
139
|
-
|
140
|
-
let(:io) {sockets.first}
|
141
|
-
subject {sockets.last}
|
142
|
-
|
143
|
-
it_should_behave_like Async::IO
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
RSpec.describe Async::IO::IPSocket do
|
148
|
-
it_should_behave_like Async::IO::Generic, [:inspect]
|
149
|
-
end
|