io-endpoint 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/io/connected.rb +27 -0
- data/lib/io/endpoint/composite_endpoint.rb +3 -3
- data/lib/io/endpoint/generic.rb +4 -12
- data/lib/io/endpoint/shared_endpoint.rb +10 -10
- data/lib/io/endpoint/ssl_endpoint.rb +6 -6
- data/lib/io/endpoint/version.rb +1 -1
- data/lib/io/endpoint/wrapper.rb +6 -7
- data.tar.gz.sig +0 -0
- metadata +4 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10203d535af830bf9ff71034262b5851ec323024a9de4db527f061cb1cd76102
|
4
|
+
data.tar.gz: b150061a0414c379afb7fb5f2c142767afc5ed1822e5b106b78ece023d1cf459
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82930d72359dee91627b19c771f79c9f2c6cc43dc93b9514a372a4568d1fb92c653ff2da1403c8519eddc4470dc14ef2356abe41cd202fba80bc35ba10e2d053
|
7
|
+
data.tar.gz: 556e87a95eb514e643a3e6bb40468ac851cceea5da6fb6f72db37767dca18882bb9b63e61e05d2e69629a1e4eef1859c3a2b3e0797b36e0e4eb1202684f8d44c
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/io/connected.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'socket'
|
2
|
+
|
3
|
+
class IO
|
4
|
+
def connected?
|
5
|
+
!closed?
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class Socket
|
10
|
+
def connected?
|
11
|
+
# Is it likely that the socket is still connected?
|
12
|
+
# May return false positive, but won't return false negative.
|
13
|
+
return false unless super
|
14
|
+
|
15
|
+
# If we can wait for the socket to become readable, we know that the socket may still be open.
|
16
|
+
result = to_io.recv_nonblock(1, MSG_PEEK, exception: false)
|
17
|
+
|
18
|
+
# No data was available - newer Ruby can return nil instead of empty string:
|
19
|
+
return false if result.nil?
|
20
|
+
|
21
|
+
# Either there was some data available, or we can wait to see if there is data avaialble.
|
22
|
+
return !result.empty? || result == :wait_readable
|
23
|
+
rescue Errno::ECONNRESET
|
24
|
+
# This might be thrown by recv_nonblock.
|
25
|
+
return false
|
26
|
+
end
|
27
|
+
end
|
@@ -18,12 +18,12 @@ module IO::Endpoint
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
def connect(&block)
|
21
|
+
def connect(wrapper = Wrapper.default, &block)
|
22
22
|
last_error = nil
|
23
23
|
|
24
24
|
@endpoints.each do |endpoint|
|
25
25
|
begin
|
26
|
-
return endpoint.connect(&block)
|
26
|
+
return endpoint.connect(wrapper, &block)
|
27
27
|
rescue => last_error
|
28
28
|
end
|
29
29
|
end
|
@@ -31,7 +31,7 @@ module IO::Endpoint
|
|
31
31
|
raise last_error
|
32
32
|
end
|
33
33
|
|
34
|
-
def bind(&block)
|
34
|
+
def bind(wrapper = Wrapper.default, &block)
|
35
35
|
if block_given?
|
36
36
|
@endpoints.each do |endpoint|
|
37
37
|
endpoint.bind(&block)
|
data/lib/io/endpoint/generic.rb
CHANGED
@@ -69,21 +69,13 @@ module IO::Endpoint
|
|
69
69
|
|
70
70
|
# Accept connections from the specified endpoint.
|
71
71
|
# @param backlog [Integer] the number of connections to listen for.
|
72
|
-
def accept(
|
73
|
-
bind do |server|
|
74
|
-
|
75
|
-
|
76
|
-
while true
|
77
|
-
socket, address = server.accept
|
78
|
-
|
79
|
-
Fiber.schedule do
|
80
|
-
yield socket, address
|
81
|
-
end
|
82
|
-
end
|
72
|
+
def accept(wrapper = Wrapper.default, *arguments, **options, &block)
|
73
|
+
bind(wrapper, *arguments, **options) do |server|
|
74
|
+
wrapper.accept(server, &block)
|
83
75
|
end
|
84
76
|
end
|
85
77
|
|
86
|
-
# Create an Endpoint instance by URI scheme. The host and port of the URI will be passed to the Endpoint factory method, along with any options
|
78
|
+
# Create an Endpoint instance by URI scheme. The host and port of the URI will be passed to the Endpoint factory method, along with any options.
|
87
79
|
#
|
88
80
|
# You should not use untrusted input as it may execute arbitrary code.
|
89
81
|
#
|
@@ -32,11 +32,11 @@ module IO::Endpoint
|
|
32
32
|
|
33
33
|
# Create a new `SharedEndpoint` by connecting to the given endpoint.
|
34
34
|
def self.connected(endpoint, close_on_exec: false)
|
35
|
-
|
35
|
+
socket = endpoint.connect
|
36
36
|
|
37
|
-
|
37
|
+
socket.close_on_exec = close_on_exec
|
38
38
|
|
39
|
-
return self.new(endpoint, [
|
39
|
+
return self.new(endpoint, [socket])
|
40
40
|
end
|
41
41
|
|
42
42
|
def initialize(endpoint, sockets, **options)
|
@@ -53,18 +53,18 @@ module IO::Endpoint
|
|
53
53
|
|
54
54
|
def local_address_endpoint(**options)
|
55
55
|
endpoints = @sockets.map do |wrapper|
|
56
|
-
AddressEndpoint.new(wrapper.to_io.local_address)
|
56
|
+
AddressEndpoint.new(wrapper.to_io.local_address, **options)
|
57
57
|
end
|
58
58
|
|
59
|
-
return CompositeEndpoint.new(endpoints
|
59
|
+
return CompositeEndpoint.new(endpoints)
|
60
60
|
end
|
61
61
|
|
62
62
|
def remote_address_endpoint(**options)
|
63
63
|
endpoints = @sockets.map do |wrapper|
|
64
|
-
AddressEndpoint.new(wrapper.to_io.remote_address)
|
64
|
+
AddressEndpoint.new(wrapper.to_io.remote_address, **options)
|
65
65
|
end
|
66
66
|
|
67
|
-
return CompositeEndpoint.new(endpoints
|
67
|
+
return CompositeEndpoint.new(endpoints)
|
68
68
|
end
|
69
69
|
|
70
70
|
# Close all the internal sockets.
|
@@ -113,9 +113,9 @@ module IO::Endpoint
|
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
|
-
def accept(
|
117
|
-
bind do |server|
|
118
|
-
|
116
|
+
def accept(wrapper = Wrapper.default, &block)
|
117
|
+
bind(wrapper) do |server|
|
118
|
+
wrapper.accept(server, &block)
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
@@ -91,14 +91,14 @@ module IO::Endpoint
|
|
91
91
|
# Connect to the underlying endpoint and establish a SSL connection.
|
92
92
|
# @yield [Socket] the socket which is being connected
|
93
93
|
# @return [Socket] the connected socket
|
94
|
-
def bind
|
94
|
+
def bind(*arguments, **options, &block)
|
95
95
|
if block_given?
|
96
|
-
@endpoint.bind do |server|
|
97
|
-
yield ::OpenSSL::SSL::SSLServer.new(server, context)
|
96
|
+
@endpoint.bind(*arguments, **options) do |server|
|
97
|
+
yield ::OpenSSL::SSL::SSLServer.new(server, self.context)
|
98
98
|
end
|
99
99
|
else
|
100
|
-
@endpoint.bind.map do |server|
|
101
|
-
::OpenSSL::SSL::SSLServer.new(server, context)
|
100
|
+
@endpoint.bind(*arguments, **options).map do |server|
|
101
|
+
::OpenSSL::SSL::SSLServer.new(server, self.context)
|
102
102
|
end
|
103
103
|
end
|
104
104
|
end
|
@@ -107,7 +107,7 @@ module IO::Endpoint
|
|
107
107
|
# @yield [Socket] the socket which is being connected
|
108
108
|
# @return [Socket] the connected socket
|
109
109
|
def connect(&block)
|
110
|
-
socket = ::OpenSSL::SSL::SSLSocket.new(@endpoint.connect, context)
|
110
|
+
socket = ::OpenSSL::SSL::SSLSocket.new(@endpoint.connect, self.context)
|
111
111
|
|
112
112
|
if hostname = self.hostname
|
113
113
|
socket.hostname = hostname
|
data/lib/io/endpoint/version.rb
CHANGED
data/lib/io/endpoint/wrapper.rb
CHANGED
@@ -30,7 +30,6 @@ module IO::Endpoint
|
|
30
30
|
# On Darwin, sometimes occurs when the connection is not yet fully formed. Empirically, TCP_NODELAY is enabled despite this result.
|
31
31
|
rescue Errno::EOPNOTSUPP
|
32
32
|
# Some platforms may simply not support the operation.
|
33
|
-
# Console.logger.warn(self) {"Unable to set sync=#{value}!"}
|
34
33
|
rescue Errno::ENOPROTOOPT
|
35
34
|
# It may not be supported by the protocol (e.g. UDP). ¯\_(ツ)_/¯
|
36
35
|
end
|
@@ -131,14 +130,14 @@ module IO::Endpoint
|
|
131
130
|
end
|
132
131
|
|
133
132
|
# Bind to a local address and accept connections in a loop.
|
134
|
-
def accept(
|
135
|
-
|
136
|
-
server.
|
133
|
+
def accept(server, timeout: server.timeout, &block)
|
134
|
+
while true
|
135
|
+
socket, address = server.accept
|
136
|
+
|
137
|
+
socket.timeout = timeout if timeout != false
|
137
138
|
|
138
139
|
async do
|
139
|
-
|
140
|
-
server.accept(&block)
|
141
|
-
end
|
140
|
+
yield socket, address
|
142
141
|
end
|
143
142
|
end
|
144
143
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: io-endpoint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -37,7 +37,7 @@ cert_chain:
|
|
37
37
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
38
38
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
39
39
|
-----END CERTIFICATE-----
|
40
|
-
date:
|
40
|
+
date: 2024-01-01 00:00:00.000000000 Z
|
41
41
|
dependencies: []
|
42
42
|
description:
|
43
43
|
email:
|
@@ -45,6 +45,7 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
+
- lib/io/connected.rb
|
48
49
|
- lib/io/endpoint.rb
|
49
50
|
- lib/io/endpoint/address_endpoint.rb
|
50
51
|
- lib/io/endpoint/composite_endpoint.rb
|
@@ -78,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
79
|
- !ruby/object:Gem::Version
|
79
80
|
version: '0'
|
80
81
|
requirements: []
|
81
|
-
rubygems_version: 3.
|
82
|
+
rubygems_version: 3.4.10
|
82
83
|
signing_key:
|
83
84
|
specification_version: 4
|
84
85
|
summary: Provides a separation of concerns interface for IO endpoints.
|
metadata.gz.sig
CHANGED
Binary file
|