async-io 1.14.0 → 1.15.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/address_endpoint.rb +5 -0
- data/lib/async/io/endpoint.rb +1 -0
- data/lib/async/io/host_endpoint.rb +11 -3
- data/lib/async/io/shared_endpoint.rb +4 -1
- data/lib/async/io/ssl_endpoint.rb +12 -2
- data/lib/async/io/ssl_socket.rb +1 -1
- data/lib/async/io/version.rb +1 -1
- data/spec/async/io/shared_endpoint_spec.rb +52 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d4d9a66fb4be7f89c7dda8e08e7e10fdc2145d52eb5310b7b0d5bf0aa657fd7
|
4
|
+
data.tar.gz: ba85706fcee621d8f23b01a67389c084c8772f759c301e6c22a165b94a2f5686
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2f682fdde7cd37a7836233bd194c7a1fca1a5f25e4f1f1bb424e95075b40a3b6d46c83ca2a92c57557e038515bb425989a11397067bf7afb2c8128ce532b514
|
7
|
+
data.tar.gz: c7fa044f6140fc47e040188d0fa66848812ea1b187935fb9fbbdc46efdff7f553037af77089e955481779c1c605396851b6aa9b1fc280a2497fd64f995304a61
|
@@ -38,10 +38,15 @@ module Async
|
|
38
38
|
attr :address
|
39
39
|
attr :options
|
40
40
|
|
41
|
+
# Bind a socket to the given address. If a block is given, the socket will be automatically closed when the block exits.
|
42
|
+
# @yield [Socket] the bound socket
|
43
|
+
# @return [Socket] the bound socket
|
41
44
|
def bind(&block)
|
42
45
|
Socket.bind(@address, **@options, &block)
|
43
46
|
end
|
44
47
|
|
48
|
+
# Connects a socket to the given address. If a block is given, the socket will be automatically closed when the block exits.
|
49
|
+
# @return [Socket] the connected socket
|
45
50
|
def connect(&block)
|
46
51
|
Socket.connect(@address, **@options, &block)
|
47
52
|
end
|
data/lib/async/io/endpoint.rb
CHANGED
@@ -37,10 +37,14 @@ module Async
|
|
37
37
|
@specification.first
|
38
38
|
end
|
39
39
|
|
40
|
+
# Try to connect to the given host by connecting to each address in sequence until a connection is made.
|
41
|
+
# @yield [Socket] the socket which is being connected, may be invoked more than once
|
42
|
+
# @return [Socket] the connected socket
|
43
|
+
# @raise if no connection could complete successfully
|
40
44
|
def connect(&block)
|
41
45
|
last_error = nil
|
42
46
|
|
43
|
-
Addrinfo.foreach(*@specification)
|
47
|
+
Addrinfo.foreach(*@specification) do |address|
|
44
48
|
begin
|
45
49
|
return Socket.connect(address, **@options, &block)
|
46
50
|
rescue
|
@@ -51,16 +55,20 @@ module Async
|
|
51
55
|
raise last_error
|
52
56
|
end
|
53
57
|
|
58
|
+
# Invokes the given block for every address which can be bound to.
|
59
|
+
# @yield [Socket] the bound socket
|
60
|
+
# @return [Array<Socket>] an array of bound sockets
|
54
61
|
def bind(&block)
|
55
|
-
Addrinfo.foreach(*@specification) do |address|
|
62
|
+
Addrinfo.foreach(*@specification).collect do |address|
|
56
63
|
Socket.bind(address, **@options, &block)
|
57
64
|
end
|
58
65
|
end
|
59
66
|
|
67
|
+
# @yield [AddressEndpoint] address endpoints by resolving the given host specification
|
60
68
|
def each
|
61
69
|
return to_enum unless block_given?
|
62
70
|
|
63
|
-
Addrinfo.foreach(*@specification)
|
71
|
+
Addrinfo.foreach(*@specification) do |address|
|
64
72
|
yield AddressEndpoint.new(address, **@options)
|
65
73
|
end
|
66
74
|
end
|
@@ -62,12 +62,22 @@ module Async
|
|
62
62
|
return context
|
63
63
|
end
|
64
64
|
|
65
|
+
# Connect to the underlying endpoint and establish a SSL connection.
|
66
|
+
# @yield [Socket] the socket which is being connected
|
67
|
+
# @return [Socket] the connected socket
|
65
68
|
def bind
|
66
|
-
|
67
|
-
|
69
|
+
if block_given?
|
70
|
+
@endpoint.bind do |server|
|
71
|
+
yield SSLServer.new(server, context)
|
72
|
+
end
|
73
|
+
else
|
74
|
+
return SSLServer.new(@endpoint.bind, context)
|
68
75
|
end
|
69
76
|
end
|
70
77
|
|
78
|
+
# Connect to the underlying endpoint and establish a SSL connection.
|
79
|
+
# @yield [Socket] the socket which is being connected
|
80
|
+
# @return [Socket] the connected socket
|
71
81
|
def connect(&block)
|
72
82
|
SSLSocket.connect(@endpoint.connect, context, hostname, &block)
|
73
83
|
end
|
data/lib/async/io/ssl_socket.rb
CHANGED
@@ -94,7 +94,7 @@ module Async
|
|
94
94
|
@context = context
|
95
95
|
end
|
96
96
|
|
97
|
-
def_delegators :@server, :local_address, :setsockopt, :getsockopt, :close
|
97
|
+
def_delegators :@server, :local_address, :setsockopt, :getsockopt, :close, :close_on_exec=, :reactor=
|
98
98
|
|
99
99
|
attr :server
|
100
100
|
attr :context
|
data/lib/async/io/version.rb
CHANGED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require 'async/io/host_endpoint'
|
22
|
+
require 'async/io/shared_endpoint'
|
23
|
+
|
24
|
+
RSpec.describe Async::IO::SharedEndpoint do
|
25
|
+
include_context Async::RSpec::Reactor
|
26
|
+
|
27
|
+
describe '#bound' do
|
28
|
+
let(:endpoint) {Async::IO::Endpoint.tcp("localhost", 5123)}
|
29
|
+
|
30
|
+
it "can bind to shared endpoint" do
|
31
|
+
bound_endpoint = described_class.bound(endpoint)
|
32
|
+
|
33
|
+
expect(bound_endpoint.wrappers).to_not be_empty
|
34
|
+
expect(bound_endpoint.wrappers.first).to be_a Async::IO::Socket
|
35
|
+
|
36
|
+
bound_endpoint.close
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#connected' do
|
41
|
+
let(:endpoint) {Async::IO::Endpoint.tcp("www.google.com", 80)}
|
42
|
+
|
43
|
+
it "can connect to shared endpoint" do
|
44
|
+
connected_endpoint = described_class.connected(endpoint)
|
45
|
+
|
46
|
+
expect(connected_endpoint.wrappers).to_not be_empty
|
47
|
+
expect(connected_endpoint.wrappers.first).to be_a Async::IO::Socket
|
48
|
+
|
49
|
+
connected_endpoint.close
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
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.
|
4
|
+
version: 1.15.0
|
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-
|
11
|
+
date: 2018-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|
@@ -133,6 +133,7 @@ files:
|
|
133
133
|
- spec/async/io/generic_spec.rb
|
134
134
|
- spec/async/io/notification_spec.rb
|
135
135
|
- spec/async/io/protocol/line_spec.rb
|
136
|
+
- spec/async/io/shared_endpoint_spec.rb
|
136
137
|
- spec/async/io/socket/tcp_spec.rb
|
137
138
|
- spec/async/io/socket/udp_spec.rb
|
138
139
|
- spec/async/io/socket_spec.rb
|
@@ -178,6 +179,7 @@ test_files:
|
|
178
179
|
- spec/async/io/generic_spec.rb
|
179
180
|
- spec/async/io/notification_spec.rb
|
180
181
|
- spec/async/io/protocol/line_spec.rb
|
182
|
+
- spec/async/io/shared_endpoint_spec.rb
|
181
183
|
- spec/async/io/socket/tcp_spec.rb
|
182
184
|
- spec/async/io/socket/udp_spec.rb
|
183
185
|
- spec/async/io/socket_spec.rb
|