tcp-client 0.14.0 → 1.0.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ed9a12e8872f2399ace7bef72451c8f6b2d7821e4de069e095eb1ca7a5fcb96
|
4
|
+
data.tar.gz: 4b6b744fb885e99ea320cdfbfe21a9ff1aceaa12beedec2f2b068ceb3e932cd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4e7417600e74d3709a20b20f5d13804da51d0ff85670ca8a180bd173ae7f07ea513976c2b73c3436a852b5c51a1f6c99a61f917c4be769cd73cb91f9b65684a
|
7
|
+
data.tar.gz: 197b43ef8e44faec4a6bcd397f71505b3f8f4714a3775248eeaf2984acca4444bd5f8e290cc99be9408870f4a862f1c724cfadd55c114be12a4651027f7d7fd4
|
@@ -7,11 +7,11 @@ rescue LoadError
|
|
7
7
|
end
|
8
8
|
|
9
9
|
require_relative 'deadline'
|
10
|
-
require_relative '
|
10
|
+
require_relative 'with_deadline'
|
11
11
|
|
12
12
|
class TCPClient
|
13
13
|
class SSLSocket < ::OpenSSL::SSL::SSLSocket
|
14
|
-
include
|
14
|
+
include WithDeadline
|
15
15
|
|
16
16
|
def initialize(socket, address, configuration, deadline, exception)
|
17
17
|
ssl_params = Hash[configuration.ssl_params]
|
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
require 'socket'
|
4
4
|
require_relative 'deadline'
|
5
|
-
require_relative '
|
5
|
+
require_relative 'with_deadline'
|
6
6
|
|
7
7
|
class TCPClient
|
8
8
|
class TCPSocket < ::Socket
|
9
|
-
include
|
9
|
+
include WithDeadline
|
10
10
|
|
11
11
|
def initialize(address, configuration, deadline, exception)
|
12
12
|
super(address.addrinfo.ipv6? ? :INET6 : :INET, :STREAM)
|
data/lib/tcp-client/version.rb
CHANGED
@@ -1,16 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class TCPClient
|
4
|
-
module
|
5
|
-
class << self
|
6
|
-
private
|
7
|
-
|
8
|
-
def included(mod)
|
9
|
-
return if defined?(mod.wait_writable) && defined?(mod.wait_readable)
|
10
|
-
mod.include(defined?(mod.to_io) ? WaitWithIO : WaitWithSelect)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
4
|
+
module WithDeadline
|
14
5
|
def read_with_deadline(nbytes, deadline, exception)
|
15
6
|
raise(exception) unless deadline.remaining_time
|
16
7
|
return fetch_avail(deadline, exception) if nbytes.nil?
|
@@ -79,10 +70,10 @@ class TCPClient
|
|
79
70
|
case ret = yield
|
80
71
|
when :wait_writable
|
81
72
|
remaining_time = deadline.remaining_time or raise(exception)
|
82
|
-
|
73
|
+
wait_write[remaining_time] or raise(exception)
|
83
74
|
when :wait_readable
|
84
75
|
remaining_time = deadline.remaining_time or raise(exception)
|
85
|
-
|
76
|
+
wait_read[remaining_time] or raise(exception)
|
86
77
|
else
|
87
78
|
return ret
|
88
79
|
end
|
@@ -91,18 +82,28 @@ class TCPClient
|
|
91
82
|
raise(exception)
|
92
83
|
end
|
93
84
|
|
94
|
-
|
95
|
-
|
96
|
-
|
85
|
+
def wait_write
|
86
|
+
@wait_write ||=
|
87
|
+
if defined?(wait_writable)
|
88
|
+
->(t) { wait_writable(t) }
|
89
|
+
elsif defined?(to_io)
|
90
|
+
->(t) { to_io.wait_writable(t) }
|
91
|
+
else
|
92
|
+
->(t) { ::IO.select(nil, [self], nil, t) }
|
93
|
+
end
|
97
94
|
end
|
98
95
|
|
99
|
-
|
100
|
-
|
101
|
-
|
96
|
+
def wait_read
|
97
|
+
@wait_read ||=
|
98
|
+
if defined?(wait_readable)
|
99
|
+
->(t) { wait_readable(t) }
|
100
|
+
elsif defined?(to_io)
|
101
|
+
->(t) { to_io.wait_readable(t) }
|
102
|
+
else
|
103
|
+
->(t) { ::IO.select([self], nil, nil, t) }
|
104
|
+
end
|
102
105
|
end
|
103
|
-
|
104
|
-
private_constant(:WaitWithIO, :WaitWithSelect)
|
105
106
|
end
|
106
107
|
|
107
|
-
private_constant(:
|
108
|
+
private_constant(:WithDeadline)
|
108
109
|
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
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Blumtritt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03
|
11
|
+
date: 2024-05-03 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
|
@@ -31,10 +31,10 @@ files:
|
|
31
31
|
- lib/tcp-client/deadline.rb
|
32
32
|
- lib/tcp-client/default_configuration.rb
|
33
33
|
- lib/tcp-client/errors.rb
|
34
|
-
- lib/tcp-client/mixin/io_with_deadline.rb
|
35
34
|
- lib/tcp-client/ssl_socket.rb
|
36
35
|
- lib/tcp-client/tcp_socket.rb
|
37
36
|
- lib/tcp-client/version.rb
|
37
|
+
- lib/tcp-client/with_deadline.rb
|
38
38
|
- lib/tcp_client.rb
|
39
39
|
homepage: https://github.com/mblumtritt/tcp-client
|
40
40
|
licenses:
|
@@ -59,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '0'
|
61
61
|
requirements: []
|
62
|
-
rubygems_version: 3.5.
|
62
|
+
rubygems_version: 3.5.9
|
63
63
|
signing_key:
|
64
64
|
specification_version: 4
|
65
65
|
summary: Use your TCP connections with working timeout.
|