tcp-client 0.11.2 → 0.11.4
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: c1aa14f6b147ad3e70a4020f9973c45682dcbe7a0d99cd4c50dbe65b2db05141
|
4
|
+
data.tar.gz: 61393c3ce4e626b2299fd1a1ab74ea7f600506ca3bde690c1b128c1a9c669eb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8831cef32985a2f41b11fd6830548badb93963df3d67a9bb0424de3e601552cc687a8b27b13433e01f88a3672bdd24df21a5bd3656b85b0ad562838b9fb2c418
|
7
|
+
data.tar.gz: d636abef03299dd92f916d54eec01414985fa87375254d6e3814d6307159bac62963591f87cb176387fcdf26ae3562df6883223c6710e9572a123af8d4f6ba70
|
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 && (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
|
-
|
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.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:
|
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.
|