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 +4 -4
- data/.yardopts +1 -1
- data/README.md +5 -5
- data/lib/tcp-client/address.rb +5 -2
- data/lib/tcp-client/deadline.rb +3 -3
- data/lib/tcp-client/mixin/io_with_deadline.rb +16 -7
- data/lib/tcp-client/version.rb +1 -1
- data/lib/tcp-client.rb +3 -4
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d7af455e50934e3a112047a9f8779993e890b44e01f100c78695ed52fdde979
|
4
|
+
data.tar.gz: f144e06f7a7e5be0c2691bfafb536a3709a0a069b6280141b876b4a6b56b118d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82f2061ef746877f1152475e836d925181353d3b6f7e4a1592dafb5d6151cd495882da17801b487ccade8c5b46dfe75b63b9d8f9b16d781a22d51cb9e79e8227
|
7
|
+
data.tar.gz: 1b42dc104cd5f9c0d02c98d4f020136658f428ce629347c7065101f55195c8f94e2bbaaf36e08a6adc74989b566f99042849c9fe2320df3a53872d8ef085528b
|
data/.yardopts
CHANGED
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/
|
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](
|
41
|
+
For more samples see [the examples dir](./examples)
|
42
42
|
|
43
43
|
## Installation
|
44
44
|
|
45
|
-
Use [Bundler](http://gembundler.com/) to
|
45
|
+
Use [Bundler](http://gembundler.com/) to add TCPClient in your own project:
|
46
46
|
|
47
|
-
|
47
|
+
Include in your `Gemfile`:
|
48
48
|
|
49
49
|
```ruby
|
50
50
|
gem 'tcp-client'
|
data/lib/tcp-client/address.rb
CHANGED
@@ -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
|
-
|
115
|
-
|
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)
|
data/lib/tcp-client/deadline.rb
CHANGED
@@ -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 :
|
7
|
+
@deadline = timeout&.positive? ? now + timeout : nil
|
8
8
|
end
|
9
9
|
|
10
10
|
def valid?
|
11
|
-
|
11
|
+
!@deadline.nil?
|
12
12
|
end
|
13
13
|
|
14
14
|
def remaining_time
|
15
|
-
|
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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
mod
|
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
|
-
|
91
|
+
wait_writable(remaining_time) or raise(exception)
|
83
92
|
when :wait_readable
|
84
93
|
remaining_time = deadline.remaining_time or raise(exception)
|
85
|
-
|
94
|
+
wait_readable(remaining_time) or raise(exception)
|
86
95
|
else
|
87
96
|
return ret
|
88
97
|
end
|
data/lib/tcp-client/version.rb
CHANGED
data/lib/tcp-client.rb
CHANGED
@@ -153,7 +153,7 @@ class TCPClient
|
|
153
153
|
#
|
154
154
|
# @return [TCPClient] itself
|
155
155
|
#
|
156
|
-
# @raise
|
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
|
-
|
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
|
-
|
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.
|
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:
|
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:
|
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
|
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.
|