tcp-client 0.4.0 → 0.4.1

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: 8d280b6685729b5f2573ec4bfb2f8d57b154275b381ef61084138e03bc5c2c2e
4
- data.tar.gz: 5bbd6d4d3b1c94fa87e44d9ae03d80e38f444e0776680eb0eb42aed60d915fd6
3
+ metadata.gz: 4a9fe010bf08d26652d93212beee9ffe55275b3b051809a3093d2ff066719372
4
+ data.tar.gz: bf23f4441be6f32d581dfb069afb09bfbb8a9ca78b90f3e0f2332f16abed89e8
5
5
  SHA512:
6
- metadata.gz: 8b7b41def4591e42fc6db859a7c5f485fc5416e266728526d59313141cfc4ccd828f7adff563a425647a61fac5bc751a1a01193bc98bef589c9b9393737c92c4
7
- data.tar.gz: 8d6d5e239dc2ba17a1015a565de2603be0f0421ee0e10fb24a94de86e5cb150d59842fd053cb27a3f58ca58fe43728f321cdfe02bba39a2c723a66ffb2013d0e
6
+ metadata.gz: c929de839e7335c4e8e950d0b96fb6028c74ba1ae6a1acec3bb4a572e54a6564d799a8ee8fdef51b77273a83a2af4c5cc29d66a4ed92c3647e1185e103d82fda
7
+ data.tar.gz: 00dacdc8d09584e1f4421c7ca62786ab617eaed1005db955ca36da4c1294738591820159d282d27e24fe3194d84e9cd5cb02b47966f231af5d5a26336bcfa366
data/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2017-2021, Mike Blumtritt. All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/lib/tcp-client.rb CHANGED
@@ -29,8 +29,8 @@ class TCPClient
29
29
  end
30
30
 
31
31
  def connect(addr, configuration, exception: nil)
32
- close
33
32
  raise(NoOpenSSL) if configuration.ssl? && !defined?(SSLSocket)
33
+ close
34
34
  @address = Address.new(addr)
35
35
  @cfg = configuration.dup
36
36
  exception ||= configuration.connect_timeout_error
@@ -89,11 +89,8 @@ class TCPClient
89
89
  private
90
90
 
91
91
  def read_with_deadline(nbytes, deadline, exception)
92
- @socket.read_with_deadline(
93
- nbytes,
94
- deadline,
95
- exception || @cfg.read_timeout_error
96
- )
92
+ exception ||= @cfg.read_timeout_error
93
+ @socket.read_with_deadline(nbytes, deadline, exception)
97
94
  end
98
95
 
99
96
  def write_with_deadline(msg, deadline, exception)
@@ -1,11 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'socket'
4
-
5
3
  class TCPClient
6
4
  class NoOpenSSL < RuntimeError
7
5
  def initialize
8
- super('OpenSSL is not avail')
6
+ super('OpenSSL is not available')
9
7
  end
10
8
  end
11
9
 
@@ -29,7 +27,7 @@ class TCPClient
29
27
 
30
28
  class NotAnException < TypeError
31
29
  def initialize(object)
32
- super("not a valid exception class - #{object.inspect}")
30
+ super("exception class required - #{object.inspect}")
33
31
  end
34
32
  end
35
33
 
@@ -17,12 +17,10 @@ class TCPClient
17
17
  ssl_params = Hash[configuration.ssl_params]
18
18
  super(socket, create_context(ssl_params))
19
19
  self.sync_close = true
20
- connect_to(
21
- address,
22
- ssl_params[:verify_mode] != OpenSSL::SSL::VERIFY_NONE,
23
- configuration.connect_timeout,
24
- exception
25
- )
20
+ self.hostname = address.hostname
21
+ deadline = Deadline.new(configuration.connect_timeout)
22
+ deadline.valid? ? connect_with_deadline(deadline, exception) : connect
23
+ post_connection_check(address.hostname) if should_verify?(ssl_params)
26
24
  end
27
25
 
28
26
  private
@@ -33,17 +31,12 @@ class TCPClient
33
31
  context
34
32
  end
35
33
 
36
- def connect_to(address, check, timeout, exception)
37
- self.hostname = address.hostname
38
- deadline = Deadline.new(timeout)
39
- if deadline.valid?
40
- with_deadline(deadline, exception) do
41
- connect_nonblock(exception: false)
42
- end
43
- else
44
- connect
45
- end
46
- post_connection_check(address.hostname) if check
34
+ def connect_with_deadline(deadline, exception)
35
+ with_deadline(deadline, exception) { connect_nonblock(exception: false) }
36
+ end
37
+
38
+ def should_verify?(ssl_params)
39
+ ssl_params[:verify_mode] != OpenSSL::SSL::VERIFY_NONE
47
40
  end
48
41
  end
49
42
 
@@ -11,18 +11,18 @@ class TCPClient
11
11
  def initialize(address, configuration, exception)
12
12
  super(address.addrinfo.ipv6? ? :INET6 : :INET, :STREAM)
13
13
  configure(configuration)
14
- connect_to(address, configuration.connect_timeout, exception)
14
+ deadline = Deadline.new(configuration.connect_timeout)
15
+ connect_to(address, deadline, exception)
15
16
  end
16
17
 
17
18
  private
18
19
 
19
- def connect_to(address, timeout, exception)
20
+ def connect_to(address, deadline, exception)
20
21
  addr =
21
22
  ::Socket.pack_sockaddr_in(
22
23
  address.addrinfo.ip_port,
23
24
  address.addrinfo.ip_address
24
25
  )
25
- deadline = Deadline.new(timeout)
26
26
  return connect(addr) unless deadline.valid?
27
27
  with_deadline(deadline, exception) do
28
28
  connect_nonblock(addr, exception: false)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class TCPClient
4
- VERSION = '0.4.0'
4
+ VERSION = '0.4.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tcp-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Blumtritt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-31 00:00:00.000000000 Z
11
+ date: 2021-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -67,6 +67,7 @@ extra_rdoc_files:
67
67
  - README.md
68
68
  files:
69
69
  - ".gitignore"
70
+ - LICENSE
70
71
  - README.md
71
72
  - gems.rb
72
73
  - lib/tcp-client.rb