tcp-client 1.0.1 → 1.0.4

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: f087df088e9bdfc71ffd19b01d3f9f7a229f4db510a339a08ea7d02c07a32eda
4
- data.tar.gz: 4b4d332dcdeb98a2bc81f3e7963973da21336e5b2d89199bfc9b0d2c92c9b122
3
+ metadata.gz: 3605cb7c8c4ae8e3da02040016d2dfb5ea74010693e802ffbb008b370a3dd3d0
4
+ data.tar.gz: 16eac136830f9cf8afc28c733e77d0de37510441b9e20d8673b484df188270cf
5
5
  SHA512:
6
- metadata.gz: f0c31448b596bc77288424a2863528714db40576f7201f2927172d0c39cac4086fe976a315347d6da78a96ca022a33e31956533caa02c025b18b7b3e3129d97d
7
- data.tar.gz: 69dd0aa063a8019c07976b6942f0d08df0f31036eb903040e63cfdc40844c0275396a879a2e7f27332ad9843b2a2ba4326fbccabee3d12e1a3b31a587cb5ba9a
6
+ metadata.gz: 76930c3206545a21c4e6276d78fa78215e48871f71c25c5c1b4661292a4236b309c1e58accb4206afff16a50aa5281cc5db6ba2ca372fc108bb64482d7a53906
7
+ data.tar.gz: f9db7319fa8988fd24ba6d456ece386e9a98431c119eef0ac3c4bba19bbe99c558147acdd3f2d457585e6b9ba447c89b704d16c6442750b23dd33179778f772b
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  BSD 3-Clause License
2
2
 
3
- Copyright (c) 2017-2021, Mike Blumtritt. All rights reserved.
3
+ Copyright (c) 2017-2025, Mike Blumtritt. All rights reserved.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
6
6
  modification, are permitted provided that the following conditions are met:
@@ -26,3 +26,4 @@ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
26
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
27
  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
28
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
+
data/README.md CHANGED
@@ -3,8 +3,8 @@
3
3
  Use your TCP connections with working timeout.
4
4
 
5
5
  - Gem: [rubygems.org](https://rubygems.org/gems/tcp-client)
6
- - Source: [github.com](https://github.com/mblumtritt/tcp-client)
7
- - Help: [rubydoc.info](https://rubydoc.info/gems/tcp-client/TCPClient)
6
+ - Source: [codeberg.org](https://codeberg.org/mblumtritt/tcp-client)
7
+ - Help: [rubydoc.info](https://rubydoc.info/gems/tcp-client/index)
8
8
 
9
9
  ## Description
10
10
 
@@ -100,18 +100,24 @@ class TCPClient
100
100
  # @return [Address] itself
101
101
  #
102
102
  def freeze
103
- return super if frozen?
103
+ return if frozen?
104
104
  solve
105
105
  @addrinfo.freeze
106
106
  @host.freeze
107
107
  super
108
108
  end
109
109
 
110
- # @!visibility private
111
- def ==(other) = to_hash == other.to_h
110
+ # @private
111
+ def ==(other)
112
+ host == other.host && port == other.port
113
+ rescue NoMethodError
114
+ false
115
+ end
116
+
117
+ # @private
112
118
  alias eql? ==
113
119
 
114
- # @!visibility private
120
+ # @private
115
121
  def equal?(other) = self.class == other.class && self == other
116
122
 
117
123
  private
@@ -119,34 +125,22 @@ class TCPClient
119
125
  def solve
120
126
  case @addr
121
127
  when self.class
122
- from_self_class(@addr)
128
+ unless @addr.frozen?
129
+ @addr = @addr.instance_variable_get(:@addr)
130
+ return solve
131
+ end
132
+ @addrinfo = @addr.addrinfo
133
+ @host = @addr.host
123
134
  when Addrinfo
124
- from_addrinfo(@addr)
135
+ @addrinfo = @addr
125
136
  when Integer
126
- from_addrinfo(Addrinfo.tcp(nil, @addr))
137
+ @addrinfo = Addrinfo.tcp(nil, @addr)
127
138
  else
128
- from_string(@addr)
129
- end
130
- @addr = nil
131
- end
132
-
133
- def from_self_class(address)
134
- unless address.frozen?
135
- @addr = address.instance_variable_get(:@addr)
136
- return solve
139
+ @host, port = host_n_port(@addr.to_s)
140
+ @addrinfo = Addrinfo.tcp(@host, port)
137
141
  end
138
- @addrinfo = address.addrinfo
139
- @host = address.host
140
- end
141
-
142
- def from_addrinfo(addrinfo)
143
- @host = (@addrinfo = addrinfo).getnameinfo(Socket::NI_NUMERICSERV).first
144
- end
145
-
146
- def from_string(str)
147
- @host, port = host_n_port(str.to_s)
148
- @addrinfo = Addrinfo.tcp(@host, port)
149
142
  @host ||= @addrinfo.getnameinfo(Socket::NI_NUMERICSERV).first
143
+ @addr = nil
150
144
  end
151
145
 
152
146
  def host_n_port(str)
@@ -43,7 +43,6 @@ class TCPClient
43
43
  #
44
44
  def initialize(options = nil)
45
45
  @buffered = @keep_alive = @reverse_lookup = true
46
- self.timeout = @ssl_params = nil
47
46
  @connect_timeout_error = ConnectTimeoutError
48
47
  @read_timeout_error = ReadTimeoutError
49
48
  @write_timeout_error = WriteTimeoutError
@@ -107,7 +106,7 @@ class TCPClient
107
106
  def ssl_params=(value)
108
107
  @ssl_params =
109
108
  if value.respond_to?(:to_hash)
110
- Hash[value.to_hash]
109
+ value.to_hash.dup
111
110
  elsif value.respond_to?(:to_h)
112
111
  value.nil? ? nil : value.to_h.dup
113
112
  else
@@ -314,24 +313,24 @@ class TCPClient
314
313
  self
315
314
  end
316
315
 
317
- # @!visibility private
316
+ # @private
318
317
  def freeze
319
318
  @ssl_params.freeze
320
319
  super
321
320
  end
322
321
 
323
- # @!visibility private
322
+ # @private
324
323
  def initialize_copy(_org)
325
324
  super
326
325
  @ssl_params = Hash[@ssl_params] if @ssl_params
327
326
  self
328
327
  end
329
328
 
330
- # @!visibility private
329
+ # @private
331
330
  def ==(other) = to_hash == other.to_h
332
331
  alias eql? ==
333
332
 
334
- # @!visibility private
333
+ # @private
335
334
  def equal?(other) = self.class == other.class && to_hash == other.to_hash
336
335
 
337
336
  private
@@ -129,19 +129,4 @@ class TCPClient
129
129
  #
130
130
  def action = :write
131
131
  end
132
-
133
- NoOpenSSL = NoOpenSSLError # @!visibility private
134
- NoBlockGiven = NoBlockGivenError # @!visibility private
135
- InvalidDeadLine = InvalidDeadLineError # @!visibility private
136
- UnknownAttribute = UnknownAttributeError # @!visibility private
137
- NotAnException = NotAnExceptionError # @!visibility private
138
- NotConnected = NotConnectedError # @!visibility private
139
- deprecate_constant(
140
- :NoOpenSSL,
141
- :NoBlockGiven,
142
- :InvalidDeadLine,
143
- :UnknownAttribute,
144
- :NotAnException,
145
- :NotConnected
146
- )
147
132
  end
@@ -53,6 +53,8 @@ class TCPClient
53
53
  CONTEXT_CACHE_MODE =
54
54
  ::OpenSSL::SSL::SSLContext::SESSION_CACHE_CLIENT |
55
55
  ::OpenSSL::SSL::SSLContext::SESSION_CACHE_NO_INTERNAL_STORE
56
+
57
+ private_constant(:CONTEXT_CACHE_MODE)
56
58
  end
57
59
 
58
60
  private_constant(:SSLSocket)
@@ -9,18 +9,17 @@ class TCPClient
9
9
  include WithDeadline
10
10
 
11
11
  def initialize(address, configuration, deadline)
12
- super(address.addrinfo.ipv6? ? :INET6 : :INET, :STREAM)
12
+ addrinfo = address.addrinfo
13
+ super(addrinfo.ipv6? ? :INET6 : :INET, :STREAM)
13
14
  configure(configuration)
14
- connect_to(as_addr_in(address), deadline)
15
+ connect_to(
16
+ ::Socket.pack_sockaddr_in(addrinfo.ip_port, addrinfo.ip_address),
17
+ deadline
18
+ )
15
19
  end
16
20
 
17
21
  private
18
22
 
19
- def as_addr_in(address)
20
- addrinfo = address.addrinfo
21
- ::Socket.pack_sockaddr_in(addrinfo.ip_port, addrinfo.ip_address)
22
- end
23
-
24
23
  def connect_to(addr, deadline)
25
24
  return connect(addr) unless deadline.valid?
26
25
  with_deadline(deadline) { connect_nonblock(addr, exception: false) }
@@ -2,5 +2,5 @@
2
2
 
3
3
  class TCPClient
4
4
  # The current version number.
5
- VERSION = '1.0.1'
5
+ VERSION = '1.0.4'
6
6
  end
@@ -6,8 +6,8 @@ class TCPClient
6
6
  deadline.remaining_time
7
7
  return fetch_avail(deadline) if nbytes.nil?
8
8
  @read_buffer ||= ''.b
9
- while @read_buffer.bytesize < nbytes
10
- read = fetch_next(deadline)
9
+ while (diff = nbytes - @read_buffer.bytesize) > 0
10
+ read = fetch_next(deadline, diff)
11
11
  read ? @read_buffer << read : (break close)
12
12
  end
13
13
  fetch_slice(nbytes)
@@ -57,8 +57,8 @@ class TCPClient
57
57
  result
58
58
  end
59
59
 
60
- def fetch_next(deadline)
61
- with_deadline(deadline) { read_nonblock(65_536, exception: false) }
60
+ def fetch_next(deadline, size = 65_536)
61
+ with_deadline(deadline) { read_nonblock(size, exception: false) }
62
62
  end
63
63
 
64
64
  def with_deadline(deadline)
data/lib/tcp-client.rb CHANGED
@@ -125,7 +125,7 @@ class TCPClient
125
125
  def close
126
126
  @socket&.close
127
127
  self
128
- rescue *NETWORK_ERRORS
128
+ rescue *@@net_errors
129
129
  self
130
130
  ensure
131
131
  @socket = @deadline = nil
@@ -338,26 +338,24 @@ class TCPClient
338
338
 
339
339
  def stem_errors(except = nil)
340
340
  yield
341
- rescue *NETWORK_ERRORS => e
341
+ rescue *@@net_errors => e
342
342
  raise unless @configuration.normalize_network_errors
343
343
  except && e.is_a?(except) ? raise : raise(NetworkError, e)
344
344
  end
345
345
 
346
- NETWORK_ERRORS =
347
- [
348
- Errno::EADDRNOTAVAIL,
349
- Errno::ECONNABORTED,
350
- Errno::ECONNREFUSED,
351
- Errno::ECONNRESET,
352
- Errno::EHOSTUNREACH,
353
- Errno::EINVAL,
354
- Errno::ENETUNREACH,
355
- Errno::EPIPE,
356
- IOError,
357
- SocketError
358
- ].tap do |errors|
359
- errors << ::OpenSSL::SSL::SSLError if defined?(::OpenSSL::SSL::SSLError)
360
- end
361
- .freeze
362
- private_constant(:NETWORK_ERRORS)
346
+ @@net_errors = [
347
+ Errno::EADDRNOTAVAIL,
348
+ Errno::ECONNABORTED,
349
+ Errno::ECONNREFUSED,
350
+ Errno::EHOSTUNREACH,
351
+ Errno::ENETUNREACH,
352
+ Errno::ECONNRESET,
353
+ Errno::EINVAL,
354
+ Errno::EPIPE,
355
+ Errno::EPERM,
356
+ SocketError,
357
+ IOError
358
+ ]
359
+ @@net_errors << ::OpenSSL::SSL::SSLError if defined?(::OpenSSL::SSL::SSLError)
360
+ @@net_errors.freeze
363
361
  end
metadata CHANGED
@@ -1,26 +1,24 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tcp-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Blumtritt
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-05-12 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies: []
13
12
  description: |
14
13
  This gem implements a customizable TCP client class that gives you control
15
14
  over time limits. You can set time limits for individual read or write calls
16
15
  or set a deadline for entire call sequences.
17
16
  It has a very small footprint, no dependencies and is easily useable.
18
- email:
19
17
  executables: []
20
18
  extensions: []
21
19
  extra_rdoc_files:
22
- - README.md
23
20
  - LICENSE
21
+ - README.md
24
22
  files:
25
23
  - ".yardopts"
26
24
  - LICENSE
@@ -36,15 +34,15 @@ files:
36
34
  - lib/tcp-client/version.rb
37
35
  - lib/tcp-client/with_deadline.rb
38
36
  - lib/tcp_client.rb
39
- homepage: https://github.com/mblumtritt/tcp-client
37
+ homepage: https://codeberg.org/mblumtritt/tcp-client
40
38
  licenses:
41
39
  - BSD-3-Clause
42
40
  metadata:
43
- source_code_uri: https://github.com/mblumtritt/tcp-client
44
- bug_tracker_uri: https://github.com/mblumtritt/tcp-client/issues
41
+ source_code_uri: https://codeberg.org/mblumtritt/tcp-client
42
+ bug_tracker_uri: https://codeberg.org/mblumtritt/tcp-client/issues
45
43
  documentation_uri: https://rubydoc.info/gems/tcp-client
46
44
  rubygems_mfa_required: 'true'
47
- post_install_message:
45
+ yard.run: yard
48
46
  rdoc_options: []
49
47
  require_paths:
50
48
  - lib
@@ -59,8 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
57
  - !ruby/object:Gem::Version
60
58
  version: '0'
61
59
  requirements: []
62
- rubygems_version: 3.5.10
63
- signing_key:
60
+ rubygems_version: 3.7.2
64
61
  specification_version: 4
65
62
  summary: Use your TCP connections with working timeout.
66
63
  test_files: []