tcp-client 1.0.1 → 1.0.2

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: a0318e4b31864c2b3f2b0af3e4d78f8d64b2d51b48eb2dd888d012583afd5f16
4
+ data.tar.gz: 5bf4683093179f1bf2a9c98ac0f208b401042b2303b8552bc98034dd138b5cb0
5
5
  SHA512:
6
- metadata.gz: f0c31448b596bc77288424a2863528714db40576f7201f2927172d0c39cac4086fe976a315347d6da78a96ca022a33e31956533caa02c025b18b7b3e3129d97d
7
- data.tar.gz: 69dd0aa063a8019c07976b6942f0d08df0f31036eb903040e63cfdc40844c0275396a879a2e7f27332ad9843b2a2ba4326fbccabee3d12e1a3b31a587cb5ba9a
6
+ metadata.gz: d582c9da10d45d722a52621f205e471f0f280a5ad0bfe0b7dc3fbb2f019d3bbf9089fe9918fedf8661655c7b20c17d5586c869739f1323528c238c7f8b576f2e
7
+ data.tar.gz: 6d2507dc23e40951647c323ce6bf53be89952fc4d7177d1c4e17300625240937100968127c222b285af7ac117844717f2cd22696a5e0c70e068d9e66e98c507e
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
+
@@ -100,10 +100,11 @@ class TCPClient
100
100
  # @return [Address] itself
101
101
  #
102
102
  def freeze
103
- return super if frozen?
104
- solve
105
- @addrinfo.freeze
106
- @host.freeze
103
+ unless frozen?
104
+ solve
105
+ @addrinfo.freeze
106
+ @host.freeze
107
+ end
107
108
  super
108
109
  end
109
110
 
@@ -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
@@ -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.2'
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,21 +1,19 @@
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.2
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: 2025-03-20 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:
@@ -44,7 +42,6 @@ metadata:
44
42
  bug_tracker_uri: https://github.com/mblumtritt/tcp-client/issues
45
43
  documentation_uri: https://rubydoc.info/gems/tcp-client
46
44
  rubygems_mfa_required: 'true'
47
- post_install_message:
48
45
  rdoc_options: []
49
46
  require_paths:
50
47
  - lib
@@ -59,8 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
56
  - !ruby/object:Gem::Version
60
57
  version: '0'
61
58
  requirements: []
62
- rubygems_version: 3.5.10
63
- signing_key:
59
+ rubygems_version: 3.6.6
64
60
  specification_version: 4
65
61
  summary: Use your TCP connections with working timeout.
66
62
  test_files: []