tcp-client 0.11.2 → 0.11.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4665e444c265a00de59f416c23db910d3ed7a96fc62ba6bf966c4e14b6564a9e
4
- data.tar.gz: 04c8e56bd884b61d5f5219233aa6bdfd7d2ce89c0f5892deebe27029e436ec4b
3
+ metadata.gz: 7d7af455e50934e3a112047a9f8779993e890b44e01f100c78695ed52fdde979
4
+ data.tar.gz: f144e06f7a7e5be0c2691bfafb536a3709a0a069b6280141b876b4a6b56b118d
5
5
  SHA512:
6
- metadata.gz: a40b4af0dbe5c65c3a52b0250206ab31442c7efd34df1916293a60299ef87f73d0bb0e3cc0ab4bd5ad4d5a401035fb7f9939f60fc0ef1873a945663387253221
7
- data.tar.gz: e4333df6c2ca755f8054bd6bee511835ae20965b1784c613f21545e4fc999f8e8b52da8d5c389528a473b779e1a9b5c87348474599daf47356e7081820da535d
6
+ metadata.gz: 82f2061ef746877f1152475e836d925181353d3b6f7e4a1592dafb5d6151cd495882da17801b487ccade8c5b46dfe75b63b9d8f9b16d781a22d51cb9e79e8227
7
+ data.tar.gz: 1b42dc104cd5f9c0d02c98d4f020136658f428ce629347c7065101f55195c8f94e2bbaaf36e08a6adc74989b566f99042849c9fe2320df3a53872d8ef085528b
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&.-(now)
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.3'
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.3
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.