tcp-client 0.11.2 → 0.11.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: 4665e444c265a00de59f416c23db910d3ed7a96fc62ba6bf966c4e14b6564a9e
4
- data.tar.gz: 04c8e56bd884b61d5f5219233aa6bdfd7d2ce89c0f5892deebe27029e436ec4b
3
+ metadata.gz: c1aa14f6b147ad3e70a4020f9973c45682dcbe7a0d99cd4c50dbe65b2db05141
4
+ data.tar.gz: 61393c3ce4e626b2299fd1a1ab74ea7f600506ca3bde690c1b128c1a9c669eb0
5
5
  SHA512:
6
- metadata.gz: a40b4af0dbe5c65c3a52b0250206ab31442c7efd34df1916293a60299ef87f73d0bb0e3cc0ab4bd5ad4d5a401035fb7f9939f60fc0ef1873a945663387253221
7
- data.tar.gz: e4333df6c2ca755f8054bd6bee511835ae20965b1784c613f21545e4fc999f8e8b52da8d5c389528a473b779e1a9b5c87348474599daf47356e7081820da535d
6
+ metadata.gz: 8831cef32985a2f41b11fd6830548badb93963df3d67a9bb0424de3e601552cc687a8b27b13433e01f88a3672bdd24df21a5bd3656b85b0ad562838b9fb2c418
7
+ data.tar.gz: d636abef03299dd92f916d54eec01414985fa87375254d6e3814d6307159bac62963591f87cb176387fcdf26ae3562df6883223c6710e9572a123af8d4f6ba70
data/.yardopts CHANGED
@@ -2,4 +2,4 @@
2
2
  --title 'tcp-client Documentation'
3
3
  --charset utf-8
4
4
  --markup markdown
5
- 'lib/**/*.rb' - 'LICENSE'
5
+ 'lib/**/*.rb' - 'README.md' 'LICENSE'
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
- # TCPClient
1
+ # TCPClient ![version](https://img.shields.io/gem/v/tcp-client?label=)
2
2
 
3
3
  Use your TCP connections with working timeout.
4
4
 
5
5
  - Gem: [rubygems.org](https://rubygems.org/gems/tcp-client)
6
6
  - Source: [github.com](https://github.com/mblumtritt/tcp-client)
7
- - Help: [rubydoc.info](https://rubydoc.info/github/mblumtritt/tcp-client/main/index)
7
+ - Help: [rubydoc.info](https://rubydoc.info/gems/tcp-client/TCPClient)
8
8
 
9
9
  ## Description
10
10
 
@@ -38,13 +38,13 @@ response =
38
38
  puts(response)
39
39
  ```
40
40
 
41
- For more samples see [the examples dir](https://github.com/mblumtritt/tcp-client/tree/main/examples)
41
+ For more samples see [the examples dir](./examples)
42
42
 
43
43
  ## Installation
44
44
 
45
- Use [Bundler](http://gembundler.com/) to use TCPClient in your own project:
45
+ Use [Bundler](http://gembundler.com/) to add TCPClient in your own project:
46
46
 
47
- Add to your `Gemfile`:
47
+ Include in your `Gemfile`:
48
48
 
49
49
  ```ruby
50
50
  gem 'tcp-client'
@@ -111,8 +111,11 @@ class TCPClient
111
111
 
112
112
  def init_from_string(str)
113
113
  @hostname, port = from_string(str.to_s)
114
- return init_from_addrinfo(Addrinfo.tcp(nil, port)) unless @hostname
115
- @addrinfo = Addrinfo.tcp(@hostname, port)
114
+ if @hostname
115
+ @addrinfo = Addrinfo.tcp(@hostname, port)
116
+ else
117
+ init_from_addrinfo(Addrinfo.tcp(nil, port)) unless @hostname
118
+ end
116
119
  end
117
120
 
118
121
  def from_string(str)
@@ -4,15 +4,15 @@ class TCPClient
4
4
  class Deadline
5
5
  def initialize(timeout)
6
6
  timeout = timeout&.to_f
7
- @deadline = timeout&.positive? ? now + timeout : 0
7
+ @deadline = timeout&.positive? ? now + timeout : nil
8
8
  end
9
9
 
10
10
  def valid?
11
- @deadline != 0
11
+ !@deadline.nil?
12
12
  end
13
13
 
14
14
  def remaining_time
15
- (@deadline != 0) && (remaining = @deadline - now) > 0 ? remaining : nil
15
+ @deadline && (remaining = @deadline - now) > 0 ? remaining : nil
16
16
  end
17
17
 
18
18
  private
@@ -2,10 +2,18 @@
2
2
 
3
3
  class TCPClient
4
4
  module IOWithDeadlineMixin
5
- def self.included(mod)
6
- methods = mod.instance_methods
7
- return if methods.index(:wait_writable) && methods.index(:wait_readable)
8
- mod.include(methods.index(:to_io) ? WaitWithIO : WaitWithSelect)
5
+ class << self
6
+ private
7
+
8
+ def included(mod)
9
+ return if supports_wait?(mod)
10
+ mod.include(method_defined?(:to_io) ? WaitWithIO : WaitWithSelect)
11
+ end
12
+
13
+ def supports_wait?(mod)
14
+ mod.method_defined?(:wait_writable) &&
15
+ mod.method_defined?(:wait_readable)
16
+ end
9
17
  end
10
18
 
11
19
  def read_with_deadline(nbytes, deadline, exception)
@@ -37,8 +45,8 @@ class TCPClient
37
45
  end
38
46
 
39
47
  def write_with_deadline(data, deadline, exception)
40
- raise(exception) unless deadline.remaining_time
41
48
  return 0 if (size = data.bytesize).zero?
49
+ raise(exception) unless deadline.remaining_time
42
50
  result = 0
43
51
  loop do
44
52
  written =
@@ -62,6 +70,7 @@ class TCPClient
62
70
  end
63
71
 
64
72
  def fetch_slice(size)
73
+ return ''.b if size.zero?
65
74
  result = @read_buffer.byteslice(0, size)
66
75
  rest = @read_buffer.bytesize - result.bytesize
67
76
  @read_buffer = rest.zero? ? nil : @read_buffer.byteslice(size, rest)
@@ -79,10 +88,10 @@ class TCPClient
79
88
  case ret = yield
80
89
  when :wait_writable
81
90
  remaining_time = deadline.remaining_time or raise(exception)
82
- raise(exception) if wait_writable(remaining_time).nil?
91
+ wait_writable(remaining_time) or raise(exception)
83
92
  when :wait_readable
84
93
  remaining_time = deadline.remaining_time or raise(exception)
85
- raise(exception) if wait_readable(remaining_time).nil?
94
+ wait_readable(remaining_time) or raise(exception)
86
95
  else
87
96
  return ret
88
97
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  class TCPClient
4
4
  # The current version number.
5
- VERSION = '0.11.2'
5
+ VERSION = '0.11.4'
6
6
  end
data/lib/tcp-client.rb CHANGED
@@ -153,7 +153,7 @@ class TCPClient
153
153
  #
154
154
  # @return [TCPClient] itself
155
155
  #
156
- # @raise {NoOpenSSLError} if SSL should be used but OpenSSL is not avail
156
+ # @raise [NoOpenSSLError] if SSL should be used but OpenSSL is not avail
157
157
  #
158
158
  # @see NetworkError
159
159
  #
@@ -225,9 +225,8 @@ class TCPClient
225
225
  def readline(separator = $/, chomp: false, timeout: nil, exception: nil)
226
226
  raise(NotConnectedError) if closed?
227
227
  deadline = create_deadline(timeout, configuration.read_timeout)
228
- unless deadline.valid?
228
+ deadline.valid? or
229
229
  return stem_errors { @socket.readline(separator, chomp: chomp) }
230
- end
231
230
  exception ||= configuration.read_timeout_error
232
231
  line =
233
232
  stem_errors(exception) do
@@ -328,7 +327,7 @@ class TCPClient
328
327
  yield
329
328
  rescue *NETWORK_ERRORS => e
330
329
  raise unless configuration.normalize_network_errors
331
- (except && e.is_a?(except)) ? raise : raise(NetworkError, e)
330
+ except && e.is_a?(except) ? raise : raise(NetworkError, e)
332
331
  end
333
332
 
334
333
  NETWORK_ERRORS =
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.11.2
4
+ version: 0.11.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Blumtritt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-30 00:00:00.000000000 Z
11
+ date: 2023-01-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  This gem implements a customizable TCP client class that gives you control
@@ -51,14 +51,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 2.7.0
54
+ version: 3.0.0
55
55
  required_rubygems_version: !ruby/object:Gem::Requirement
56
56
  requirements:
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
59
  version: '0'
60
60
  requirements: []
61
- rubygems_version: 3.3.7
61
+ rubygems_version: 3.4.3
62
62
  signing_key:
63
63
  specification_version: 4
64
64
  summary: Use your TCP connections with working timeout.