io-endpoint 0.5.0 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 204ed5172990d0df3a5d02e63b8e75d8caaf161808fea4e99b67f0d422241cc6
4
- data.tar.gz: 7ba7e7052949565c4cb327076c493db15d6f3057493f93d4210ec5ac5bc7808b
3
+ metadata.gz: 3f76dc33db329c9e393c817dbc679a3d06c1f523eda8740edd25447ed39f5a1b
4
+ data.tar.gz: 3917511b6a08184cad66e734120d8ea039b15645b9f0c1b256a5149372628e56
5
5
  SHA512:
6
- metadata.gz: 12aa8f963bc0787de988e9efcf80fbff38a857e8130e663ed8c329402048ab9e1940dcc2637f17de2f77f43d9222914808b5ec89e91420ed0d07475dbabc9d0e
7
- data.tar.gz: ce830974878205da1f7e91378af0bdb05f1a4017cc60715c2dca5607573992f38d97712e6b879d99ab31db95a5b12c40ab3df959da12cc56f4b2189dd37b314e
6
+ metadata.gz: 9b685cf7785946c7a856eaf7859ce6c8427c0ad1df532b188c1049432b474afd289fe7e31eff9ee6c4c608d42022b84e48d4b963de563b83482a6daa572520e8
7
+ data.tar.gz: f2a96e35cce3eea736e3ac25eabd3674d595753cdfa3caa652f28da4e9793d7d7d51d3518731018ac19716c779092eaea90d51813504cadca6193a64709fe4e1
checksums.yaml.gz.sig CHANGED
Binary file
@@ -17,7 +17,7 @@ module OpenSSL
17
17
  end
18
18
  end
19
19
 
20
- unless method_defined?(:close_on_exec)
20
+ unless method_defined?(:local_address)
21
21
  def local_address
22
22
  to_io.local_address
23
23
  end
@@ -5,6 +5,6 @@
5
5
 
6
6
  class IO
7
7
  module Endpoint
8
- VERSION = "0.5.0"
8
+ VERSION = "0.7.0"
9
9
  end
10
10
  end
@@ -147,11 +147,17 @@ module IO::Endpoint
147
147
  end
148
148
 
149
149
  # Bind to a local address and accept connections in a loop.
150
- def accept(server, timeout: nil, &block)
150
+ def accept(server, timeout: nil, linger: nil, **options, &block)
151
151
  while true
152
152
  socket, address = server.accept
153
153
 
154
- set_timeout(socket, timeout) if timeout != false
154
+ if linger
155
+ socket.setsockopt(SOL_SOCKET, SO_LINGER, 1)
156
+ end
157
+
158
+ if timeout
159
+ set_timeout(socket, timeout)
160
+ end
155
161
 
156
162
  async do
157
163
  yield socket, address
data/lib/io/endpoint.rb CHANGED
@@ -7,6 +7,8 @@ require_relative "endpoint/version"
7
7
  require_relative "endpoint/generic"
8
8
  require_relative "endpoint/shared_endpoint"
9
9
 
10
+ require_relative 'readable'
11
+
10
12
  module IO::Endpoint
11
13
  def self.file_descriptor_limit
12
14
  Process.getrlimit(Process::RLIMIT_NOFILE).first
@@ -0,0 +1,56 @@
1
+ class IO
2
+ unless method_defined?(:readable?)
3
+ def readable?
4
+ if self.wait_readable(0).nil?
5
+ # timeout means it is not eof
6
+ return true
7
+ else
8
+ !self.eof?
9
+ end
10
+ end
11
+ end
12
+ end
13
+
14
+ require 'socket'
15
+
16
+ class BasicSocket
17
+ unless method_defined?(:readable?)
18
+ def readable?
19
+ # Is it likely that the socket is still connected?
20
+ # May return false positive, but won't return false negative.
21
+ return false unless super
22
+
23
+ # If we can wait for the socket to become readable, we know that the socket may still be open.
24
+ result = to_io.recv_nonblock(1, MSG_PEEK, exception: false)
25
+
26
+ # No data was available - newer Ruby can return nil instead of empty string:
27
+ return false if result.nil?
28
+
29
+ # Either there was some data available, or we can wait to see if there is data avaialble.
30
+ return !result.empty? || result == :wait_readable
31
+ rescue Errno::ECONNRESET
32
+ # This might be thrown by recv_nonblock.
33
+ return false
34
+ end
35
+ end
36
+ end
37
+
38
+ require 'stringio'
39
+
40
+ class StringIO
41
+ unless method_defined?(:readable?)
42
+ def readable?
43
+ !eof?
44
+ end
45
+ end
46
+ end
47
+
48
+ require 'openssl'
49
+
50
+ class OpenSSL::SSL::SSLSocket
51
+ unless method_defined?(:readable?)
52
+ def readable?
53
+ to_io.readable?
54
+ end
55
+ end
56
+ 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.5.0
4
+ version: 0.7.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: 2024-01-25 00:00:00.000000000 Z
40
+ date: 2024-04-20 00:00:00.000000000 Z
41
41
  dependencies: []
42
42
  description:
43
43
  email:
@@ -45,7 +45,6 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
- - lib/io/connected.rb
49
48
  - lib/io/endpoint.rb
50
49
  - lib/io/endpoint/address_endpoint.rb
51
50
  - lib/io/endpoint/bound_endpoint.rb
@@ -59,6 +58,7 @@ files:
59
58
  - lib/io/endpoint/unix_endpoint.rb
60
59
  - lib/io/endpoint/version.rb
61
60
  - lib/io/endpoint/wrapper.rb
61
+ - lib/io/readable.rb
62
62
  - license.md
63
63
  - readme.md
64
64
  homepage: https://github.com/socketry/io-endpoint
metadata.gz.sig CHANGED
Binary file
data/lib/io/connected.rb DELETED
@@ -1,27 +0,0 @@
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