async-io 1.5.0 → 1.6.0
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/lib/async/io/endpoint.rb +42 -6
- data/lib/async/io/socket.rb +5 -1
- data/lib/async/io/version.rb +1 -1
- data/spec/async/io/endpoint_spec.rb +12 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0533045130d08f4efcc4ec788691d9801e17a6a3e5839c248cde817f34d9c196
|
4
|
+
data.tar.gz: 69c5ea7541d750da46fc4f8a8f906ec00db8420959597f1c5f621687fafa24a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37043c14010bbc1d9aaf0a6f9d0cc63337a0bb9f37c39265db3c93761e769e4e7a1a5bd716fc8171f9da76d6bb18f7df2cfb4ea9496c56e0fd83d0eb1fbb86ab
|
7
|
+
data.tar.gz: 1cc08b4414cce0946893ad48e25d65767fe5c76a517330445de2b73d0a8b7f2bcf06fbda85ce2ae62a5f53dbb914472a9f098a15726f7160e3eac53c15bbfc36
|
data/lib/async/io/endpoint.rb
CHANGED
@@ -25,6 +25,16 @@ require 'uri'
|
|
25
25
|
module Async
|
26
26
|
module IO
|
27
27
|
class Endpoint
|
28
|
+
def initialize(**options)
|
29
|
+
@options = options
|
30
|
+
end
|
31
|
+
|
32
|
+
attr :options
|
33
|
+
|
34
|
+
def hostname
|
35
|
+
@options[:hostname]
|
36
|
+
end
|
37
|
+
|
28
38
|
def self.parse(string, **options)
|
29
39
|
uri = URI.parse(string)
|
30
40
|
|
@@ -94,8 +104,17 @@ module Async
|
|
94
104
|
|
95
105
|
class HostEndpoint < Endpoint
|
96
106
|
def initialize(specification, **options)
|
107
|
+
super(**options)
|
108
|
+
|
97
109
|
@specification = specification
|
98
|
-
|
110
|
+
end
|
111
|
+
|
112
|
+
def to_s
|
113
|
+
"\#<#{self.class} #{@specification.inspect}>"
|
114
|
+
end
|
115
|
+
|
116
|
+
def hostname
|
117
|
+
@specification.first
|
99
118
|
end
|
100
119
|
|
101
120
|
def connect(&block)
|
@@ -130,10 +149,16 @@ module Async
|
|
130
149
|
# This class will open and close the socket automatically.
|
131
150
|
class AddressEndpoint < Endpoint
|
132
151
|
def initialize(address, **options)
|
152
|
+
super(**options)
|
153
|
+
|
133
154
|
@address = address
|
134
155
|
@options = options
|
135
156
|
end
|
136
157
|
|
158
|
+
def to_s
|
159
|
+
"\#<#{self.class} #{@address.inspect}>"
|
160
|
+
end
|
161
|
+
|
137
162
|
attr :address
|
138
163
|
attr :options
|
139
164
|
|
@@ -148,17 +173,22 @@ module Async
|
|
148
173
|
|
149
174
|
class SecureEndpoint < Endpoint
|
150
175
|
def initialize(endpoint, **options)
|
176
|
+
super(**options)
|
177
|
+
|
151
178
|
@endpoint = endpoint
|
152
|
-
@options = options
|
153
179
|
end
|
154
180
|
|
155
|
-
|
156
|
-
|
181
|
+
def to_s
|
182
|
+
"\#<#{self.class} #{@endpoint}>"
|
183
|
+
end
|
157
184
|
|
158
185
|
def hostname
|
159
|
-
|
186
|
+
endpoint.hostname
|
160
187
|
end
|
161
188
|
|
189
|
+
attr :endpoint
|
190
|
+
attr :options
|
191
|
+
|
162
192
|
def params
|
163
193
|
@options[:ssl_params]
|
164
194
|
end
|
@@ -201,11 +231,17 @@ module Async
|
|
201
231
|
|
202
232
|
# This class doesn't exert ownership over the specified socket, wraps a native ::IO.
|
203
233
|
class SocketEndpoint < Endpoint
|
204
|
-
def initialize(socket)
|
234
|
+
def initialize(socket, **options)
|
235
|
+
super(**options)
|
236
|
+
|
205
237
|
# This socket should already be in the required state.
|
206
238
|
@socket = Async::IO.try_convert(socket)
|
207
239
|
end
|
208
240
|
|
241
|
+
def to_s
|
242
|
+
"\#<#{self.class} #{@socket.inspect}>"
|
243
|
+
end
|
244
|
+
|
209
245
|
attr :socket
|
210
246
|
|
211
247
|
def bind(&block)
|
data/lib/async/io/socket.rb
CHANGED
@@ -43,7 +43,7 @@ module Async
|
|
43
43
|
|
44
44
|
while true
|
45
45
|
self.accept(task: task) do |io, address|
|
46
|
-
yield io, address
|
46
|
+
yield io, address, task: task
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
@@ -105,6 +105,8 @@ module Async
|
|
105
105
|
# @param local_address [Addrinfo] The local address to bind to before connecting.
|
106
106
|
# @option protcol [Integer] The socket protocol to use.
|
107
107
|
def self.connect(remote_address, local_address = nil, reuse_port: false, task: Task.current, **options)
|
108
|
+
# Async.logger.debug(self) {"Connecting to #{remote_address.inspect}"}
|
109
|
+
|
108
110
|
task.annotate "connecting to #{remote_address.inspect}"
|
109
111
|
|
110
112
|
wrapper = build(remote_address.afamily, remote_address.socktype, remote_address.protocol, **options) do |socket|
|
@@ -141,6 +143,8 @@ module Async
|
|
141
143
|
# @option protocol [Integer] The socket protocol to use.
|
142
144
|
# @option reuse_port [Boolean] Allow this port to be bound in multiple processes.
|
143
145
|
def self.bind(local_address, protocol: 0, reuse_port: false, task: Task.current, **options, &block)
|
146
|
+
Async.logger.debug(self) {"Binding to #{local_address.inspect}"}
|
147
|
+
|
144
148
|
wrapper = build(local_address.afamily, local_address.socktype, protocol, **options) do |socket|
|
145
149
|
socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_REUSEADDR, true)
|
146
150
|
socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_REUSEPORT, true) if reuse_port
|
data/lib/async/io/version.rb
CHANGED
@@ -30,6 +30,18 @@ RSpec.describe Async::IO::Endpoint do
|
|
30
30
|
expect(server.local_address.socktype).to be == ::Socket::SOCK_STREAM
|
31
31
|
end
|
32
32
|
end
|
33
|
+
|
34
|
+
it "should print nicely" do
|
35
|
+
expect(subject.to_s).to include('0.0.0.0', '5234')
|
36
|
+
end
|
37
|
+
|
38
|
+
it "has options" do
|
39
|
+
expect(subject.options[:reuse_port]).to be true
|
40
|
+
end
|
41
|
+
|
42
|
+
it "has hostname" do
|
43
|
+
expect(subject.hostname).to be == '0.0.0.0'
|
44
|
+
end
|
33
45
|
end
|
34
46
|
|
35
47
|
describe Async::IO::SocketEndpoint.new(TCPServer.new('0.0.0.0', 1234)) do
|
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.6.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-03-
|
11
|
+
date: 2018-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|