tcp-client 0.9.3 → 0.9.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 +4 -4
- data/lib/tcp-client/address.rb +15 -6
- data/lib/tcp-client/configuration.rb +31 -36
- data/lib/tcp-client/deadline.rb +1 -3
- data/lib/tcp-client/errors.rb +12 -6
- data/lib/tcp-client/version.rb +1 -1
- data/lib/tcp-client.rb +32 -33
- data/spec/tcp-client/address_spec.rb +15 -28
- data/spec/tcp-client/configuration_spec.rb +4 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 114da301d59fc9cf9c3d3bda508f4d23b5b4991877a5dc7504d4da97114f8e7f
|
4
|
+
data.tar.gz: 9d0815501de340b485cba157aff05097597948d023a7eca6c45a8ead3a4e3d0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a560644d578cedccaf1e2665f518b3a6a4e225886cfc561a8b62087420d93b958ee4741d8efde3b456fa15ce24fd5ee2f6a1121b55855205ffae5abf17becf97
|
7
|
+
data.tar.gz: f1f0ed0b87f8ee9c9b376b6b567c45aecb204c5b3de044c97f6ba080071c3c8e70da8bca8cca2484d5ddec06df181ee4b007e9ed826045e205d77df38eefbbbd
|
data/lib/tcp-client/address.rb
CHANGED
@@ -62,19 +62,28 @@ class TCPClient
|
|
62
62
|
@addrinfo.freeze
|
63
63
|
end
|
64
64
|
|
65
|
+
#
|
66
|
+
# @attribute [r] port
|
67
|
+
# @return [Integer] the port number
|
68
|
+
#
|
69
|
+
def port
|
70
|
+
@addrinfo.ip_port
|
71
|
+
end
|
72
|
+
|
65
73
|
#
|
66
74
|
# @return [String] text representation of self as "host:port"
|
67
75
|
#
|
68
76
|
def to_s
|
69
|
-
|
70
|
-
"#{@hostname}:#{@addrinfo.ip_port}"
|
77
|
+
hostname.index(':') ? "[#{hostname}]:#{port}" : "#{hostname}:#{port}"
|
71
78
|
end
|
72
79
|
|
73
80
|
#
|
74
|
-
#
|
81
|
+
# Convert `self` to a Hash containing host and port attribute.
|
82
|
+
#
|
83
|
+
# @return [Hash] host and port
|
75
84
|
#
|
76
85
|
def to_h
|
77
|
-
{ host:
|
86
|
+
{ host: hostname, port: port }
|
78
87
|
end
|
79
88
|
|
80
89
|
# @!visibility private
|
@@ -96,7 +105,7 @@ class TCPClient
|
|
96
105
|
end
|
97
106
|
|
98
107
|
def init_from_addrinfo(addrinfo)
|
99
|
-
@hostname
|
108
|
+
@hostname = addrinfo.getnameinfo(Socket::NI_NUMERICSERV).first
|
100
109
|
@addrinfo = addrinfo
|
101
110
|
end
|
102
111
|
|
@@ -109,7 +118,7 @@ class TCPClient
|
|
109
118
|
def from_string(str)
|
110
119
|
idx = str.rindex(':') or return nil, str.to_i
|
111
120
|
name = str[0, idx].delete_prefix('[').delete_suffix(']')
|
112
|
-
[name, str[idx + 1, str.size - idx].to_i]
|
121
|
+
[name.empty? ? nil : name, str[idx + 1, str.size - idx].to_i]
|
113
122
|
end
|
114
123
|
end
|
115
124
|
end
|
@@ -6,24 +6,14 @@ class TCPClient
|
|
6
6
|
#
|
7
7
|
# A Configuration is used to configure the behavior of a {TCPClient} instance.
|
8
8
|
#
|
9
|
-
# It allows to specify
|
9
|
+
# It allows to specify the monitor timeout, how to handle exceptions, if SSL
|
10
10
|
# should be used and to setup the underlying Socket.
|
11
11
|
#
|
12
12
|
class Configuration
|
13
13
|
#
|
14
|
-
#
|
15
|
-
# Shorthand to create a new configuration with given options.
|
16
|
-
#
|
17
|
-
# @example
|
18
|
-
# config = TCPClient::Configuration.create(buffered: false)
|
19
|
-
#
|
20
|
-
# @param options [Hash] see {#initialize} for details
|
21
|
-
#
|
22
|
-
# @return [Configuration] the initialized configuration
|
23
|
-
#
|
24
|
-
# @overload create(&block)
|
25
|
-
# Shorthand to create a new configuration within a code block.
|
14
|
+
# Shorthand to create a new configuration.
|
26
15
|
#
|
16
|
+
# @overload create()
|
27
17
|
# @example
|
28
18
|
# config = TCPClient::Configuration.create do |cfg|
|
29
19
|
# cfg.buffered = false
|
@@ -32,7 +22,13 @@ class TCPClient
|
|
32
22
|
#
|
33
23
|
# @yieldparam configuration {Configuration}
|
34
24
|
#
|
35
|
-
#
|
25
|
+
# @overload create(options)
|
26
|
+
# @example
|
27
|
+
# config = TCPClient::Configuration.create(buffered: false)
|
28
|
+
#
|
29
|
+
# @param options [Hash<Symbol,Object>] see {#initialize} for details
|
30
|
+
#
|
31
|
+
# @return [Configuration] the initialized configuration
|
36
32
|
#
|
37
33
|
def self.create(options = {})
|
38
34
|
configuration = new(options)
|
@@ -43,18 +39,19 @@ class TCPClient
|
|
43
39
|
#
|
44
40
|
# Intializes the instance with given options.
|
45
41
|
#
|
46
|
-
# @param options [Hash]
|
42
|
+
# @param options [Hash<Symbol,Object>]
|
47
43
|
# @option options [Boolean] :buffered, see {#buffered}
|
48
44
|
# @option options [Boolean] :keep_alive, see {#keep_alive}
|
49
45
|
# @option options [Boolean] :reverse_lookup, see {#reverse_lookup}
|
50
46
|
# @option options [Hash<Symbol, Object>] :ssl_params, see {#ssl_params}
|
51
47
|
# @option options [Numeric] :connect_timeout, see {#connect_timeout}
|
52
|
-
# @option options [Exception] :connect_timeout_error, see
|
48
|
+
# @option options [Class<Exception>] :connect_timeout_error, see
|
53
49
|
# {#connect_timeout_error}
|
54
50
|
# @option options [Numeric] :read_timeout, see {#read_timeout}
|
55
|
-
# @option options [Exception] :read_timeout_error, see
|
51
|
+
# @option options [Class<Exception>] :read_timeout_error, see
|
52
|
+
# {#read_timeout_error}
|
56
53
|
# @option options [Numeric] :write_timeout, see {#write_timeout}
|
57
|
-
# @option options [Exception] :write_timeout_error, see
|
54
|
+
# @option options [Class<Exception>] :write_timeout_error, see
|
58
55
|
# {#write_timeout_error}
|
59
56
|
# @option options [Boolean] :normalize_network_errors, see
|
60
57
|
# {#normalize_network_errors}
|
@@ -75,9 +72,8 @@ class TCPClient
|
|
75
72
|
#
|
76
73
|
# Enables/disables use of Socket-level buffering
|
77
74
|
#
|
78
|
-
# @return [
|
79
|
-
# (default)
|
80
|
-
# @return [false] if buffering is not allowed
|
75
|
+
# @return [Boolean] wheter the connection is allowed to use internal buffers
|
76
|
+
# (default) or not
|
81
77
|
#
|
82
78
|
attr_reader :buffered
|
83
79
|
|
@@ -88,9 +84,8 @@ class TCPClient
|
|
88
84
|
#
|
89
85
|
# Enables/disables use of Socket-level keep alive handling.
|
90
86
|
#
|
91
|
-
# @return [
|
92
|
-
# (default)
|
93
|
-
# @return [false] if the connection should not check keep alive
|
87
|
+
# @return [Boolean] wheter the connection is allowed to use keep alive
|
88
|
+
# signals (default) or not
|
94
89
|
#
|
95
90
|
attr_reader :keep_alive
|
96
91
|
|
@@ -101,9 +96,8 @@ class TCPClient
|
|
101
96
|
#
|
102
97
|
# Enables/disables address lookup.
|
103
98
|
#
|
104
|
-
# @return [
|
105
|
-
# (default)
|
106
|
-
# @return [false] if the address lookup is not required
|
99
|
+
# @return [Boolean] wheter the connection is allowed to lookup the address
|
100
|
+
# (default) or not
|
107
101
|
#
|
108
102
|
attr_reader :reverse_lookup
|
109
103
|
|
@@ -120,7 +114,8 @@ class TCPClient
|
|
120
114
|
end
|
121
115
|
|
122
116
|
#
|
123
|
-
# Parameters used to initialize a SSL context.
|
117
|
+
# Parameters used to initialize a SSL context. SSL/TLS will only be used if
|
118
|
+
# this attribute is not `nil`.
|
124
119
|
#
|
125
120
|
# @return [Hash<Symbol, Object>] SSL parameters for the SSL context
|
126
121
|
# @return [nil] if no SSL should be used (default)
|
@@ -161,7 +156,7 @@ class TCPClient
|
|
161
156
|
# The exception class which will be raised if {TCPClient#connect} can not
|
162
157
|
# be finished in time.
|
163
158
|
#
|
164
|
-
# @return [Class] exception class raised
|
159
|
+
# @return [Class<Exception>] exception class raised
|
165
160
|
# @raise [NotAnExceptionError] if given argument is not an Exception class
|
166
161
|
#
|
167
162
|
attr_reader :connect_timeout_error
|
@@ -189,7 +184,7 @@ class TCPClient
|
|
189
184
|
# The exception class which will be raised if {TCPClient#read} can not be
|
190
185
|
# finished in time.
|
191
186
|
#
|
192
|
-
# @return [Class] exception class raised
|
187
|
+
# @return [Class<Exception>] exception class raised
|
193
188
|
# @raise [NotAnExceptionError] if given argument is not an Exception class
|
194
189
|
#
|
195
190
|
attr_reader :read_timeout_error
|
@@ -217,7 +212,7 @@ class TCPClient
|
|
217
212
|
# The exception class which will be raised if {TCPClient#write} can not be
|
218
213
|
# finished in time.
|
219
214
|
#
|
220
|
-
# @return [Class] exception class raised
|
215
|
+
# @return [Class<Exception>] exception class raised
|
221
216
|
# @raise [NotAnExceptionError] if given argument is not an Exception class
|
222
217
|
#
|
223
218
|
attr_reader :write_timeout_error
|
@@ -244,9 +239,10 @@ class TCPClient
|
|
244
239
|
|
245
240
|
#
|
246
241
|
# @attribute [w] timeout_error
|
247
|
-
# Shorthand to set the exception class wich will by raised by any
|
242
|
+
# Shorthand to set the exception class wich will by raised by any reached
|
243
|
+
# timeout.
|
248
244
|
#
|
249
|
-
# @return [Class] exception class raised
|
245
|
+
# @return [Class<Exception>] exception class raised
|
250
246
|
#
|
251
247
|
# @raise [NotAnExceptionError] if given argument is not an Exception class
|
252
248
|
#
|
@@ -270,9 +266,8 @@ class TCPClient
|
|
270
266
|
# manner. If this option is set to true all these error cases are raised as
|
271
267
|
# {NetworkError} and can be easily captured.
|
272
268
|
#
|
273
|
-
# @return [
|
274
|
-
# {NetworkError}
|
275
|
-
# @return [false] if socket/system errors should not be normalzed (default)
|
269
|
+
# @return [Boolean] wheter all network exceptions should be raised as
|
270
|
+
# {NetworkError}, or not (default)
|
276
271
|
#
|
277
272
|
attr_reader :normalize_network_errors
|
278
273
|
|
data/lib/tcp-client/deadline.rb
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
class TCPClient
|
4
4
|
class Deadline
|
5
|
-
MONOTONIC = defined?(Process::CLOCK_MONOTONIC) ? true : false
|
6
|
-
|
7
5
|
def initialize(timeout)
|
8
6
|
timeout = timeout&.to_f
|
9
7
|
@deadline = timeout&.positive? ? now + timeout : 0
|
@@ -19,7 +17,7 @@ class TCPClient
|
|
19
17
|
|
20
18
|
private
|
21
19
|
|
22
|
-
if
|
20
|
+
if defined?(Process::CLOCK_MONOTONIC)
|
23
21
|
def now
|
24
22
|
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
25
23
|
end
|
data/lib/tcp-client/errors.rb
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
class TCPClient
|
4
4
|
#
|
5
|
-
# Raised when a SSL connection should be establshed but the OpenSSL gem is
|
5
|
+
# Raised when a SSL connection should be establshed but the OpenSSL gem is
|
6
|
+
# not available.
|
6
7
|
#
|
7
8
|
class NoOpenSSLError < RuntimeError
|
8
9
|
def initialize
|
@@ -11,7 +12,8 @@ class TCPClient
|
|
11
12
|
end
|
12
13
|
|
13
14
|
#
|
14
|
-
# Raised when a method requires a callback block but no such block is
|
15
|
+
# Raised when a method requires a callback block but no such block is
|
16
|
+
# specified.
|
15
17
|
#
|
16
18
|
class NoBlockGivenError < ArgumentError
|
17
19
|
def initialize
|
@@ -58,15 +60,18 @@ class TCPClient
|
|
58
60
|
#
|
59
61
|
# Base exception class for all network related errors.
|
60
62
|
#
|
61
|
-
# Will be raised for any system level network error when
|
63
|
+
# Will be raised for any system level network error when
|
64
|
+
# {Configuration.normalize_network_errors} is configured.
|
62
65
|
#
|
63
|
-
# You should catch this exception class when you like to handle any relevant
|
66
|
+
# You should catch this exception class when you like to handle any relevant
|
67
|
+
# {TCPClient} error.
|
64
68
|
#
|
65
69
|
class NetworkError < StandardError
|
66
70
|
end
|
67
71
|
|
68
72
|
#
|
69
|
-
# Raised when a {TCPClient} instance should read/write from/to the network
|
73
|
+
# Raised when a {TCPClient} instance should read/write from/to the network
|
74
|
+
# but is not connected.
|
70
75
|
#
|
71
76
|
class NotConnectedError < NetworkError
|
72
77
|
def initialize
|
@@ -77,7 +82,8 @@ class TCPClient
|
|
77
82
|
#
|
78
83
|
# Base exception class for a detected timeout.
|
79
84
|
#
|
80
|
-
# You should catch this exception class when you like to handle any timeout
|
85
|
+
# You should catch this exception class when you like to handle any timeout
|
86
|
+
# error.
|
81
87
|
#
|
82
88
|
class TimeoutError < NetworkError
|
83
89
|
#
|
data/lib/tcp-client/version.rb
CHANGED
data/lib/tcp-client.rb
CHANGED
@@ -30,6 +30,14 @@ class TCPClient
|
|
30
30
|
#
|
31
31
|
# If no `configuration` is given, the {.default_configuration} will be used.
|
32
32
|
#
|
33
|
+
# @overload open(address, configuration = nil)
|
34
|
+
# @yieldparam client [TCPClient] the connected client
|
35
|
+
#
|
36
|
+
# @return [Object] the block result
|
37
|
+
#
|
38
|
+
# @overload open(address, configuration = nil)
|
39
|
+
# @return [TCPClient] the connected client
|
40
|
+
#
|
33
41
|
# If an optional block is given, then the block's result is returned and the
|
34
42
|
# connection will be closed when the block execution ends.
|
35
43
|
# This can be used to create an ad-hoc connection which is garanteed to be
|
@@ -38,15 +46,10 @@ class TCPClient
|
|
38
46
|
# If no block is giiven the connected client instance is returned.
|
39
47
|
# This can be used as a shorthand to create & connect a client.
|
40
48
|
#
|
41
|
-
# @param address [Address, String, Addrinfo, Integer] the address
|
42
|
-
#
|
49
|
+
# @param address [Address, String, Addrinfo, Integer] the target address see
|
50
|
+
# {Address#initialize} for valid formats
|
43
51
|
# @param configuration [Configuration] the {Configuration} to be used for
|
44
|
-
#
|
45
|
-
#
|
46
|
-
# @yieldparam client [TCPClient] the connected client
|
47
|
-
# @yieldreturn [Object] any result
|
48
|
-
#
|
49
|
-
# @return [Object, TCPClient] the block result or the connected client
|
52
|
+
# the new instance
|
50
53
|
#
|
51
54
|
# @see #connect
|
52
55
|
#
|
@@ -59,8 +62,8 @@ class TCPClient
|
|
59
62
|
end
|
60
63
|
|
61
64
|
#
|
62
|
-
# Yields
|
63
|
-
# `address`.It limits all {#read} and {#write} actions within the block to
|
65
|
+
# Yields an instance which is connected to the server on the given
|
66
|
+
# `address`. It limits all {#read} and {#write} actions within the block to
|
64
67
|
# the given time.
|
65
68
|
#
|
66
69
|
# It ensures to close the connection when the block execution ends and returns
|
@@ -68,19 +71,18 @@ class TCPClient
|
|
68
71
|
#
|
69
72
|
# This can be used to create an ad-hoc connection which is garanteed to be
|
70
73
|
# closed and which {#read}/{#write} call sequence should not last longer than
|
71
|
-
# the `timeout
|
74
|
+
# the `timeout` seconds.
|
72
75
|
#
|
73
76
|
# If no `configuration` is given, the {.default_configuration} will be used.
|
74
77
|
#
|
75
78
|
# @param timeout [Numeric] maximum time in seconds for all {#read} and
|
76
79
|
# {#write} calls within the block
|
77
|
-
# @param address [Address, String, Addrinfo, Integer] the address
|
78
|
-
#
|
80
|
+
# @param address [Address, String, Addrinfo, Integer] the target address see
|
81
|
+
# {Address#initialize} for valid formats
|
79
82
|
# @param configuration [Configuration] the {Configuration} to be used for
|
80
|
-
#
|
83
|
+
# the instance
|
81
84
|
#
|
82
85
|
# @yieldparam client [TCPClient] the connected client
|
83
|
-
# @yieldreturn [Object] any result
|
84
86
|
#
|
85
87
|
# @return [Object] the block's result
|
86
88
|
#
|
@@ -110,7 +112,7 @@ class TCPClient
|
|
110
112
|
|
111
113
|
#
|
112
114
|
# @!parse attr_reader :closed?
|
113
|
-
# @return [Boolean]
|
115
|
+
# @return [Boolean] wheter the connection is closed
|
114
116
|
#
|
115
117
|
def closed?
|
116
118
|
@socket.nil? || @socket.closed?
|
@@ -133,21 +135,19 @@ class TCPClient
|
|
133
135
|
#
|
134
136
|
# Establishes a new connection to a given `address`.
|
135
137
|
#
|
136
|
-
# It accepts a connection-specific configuration or uses the
|
137
|
-
# {.default_configuration}.
|
138
|
-
# be a copy of the configuration used for this method call. This allows to
|
139
|
-
# configure the behavior per connection.
|
138
|
+
# It accepts a connection-specific `configuration` or uses the
|
139
|
+
# {.default_configuration}.
|
140
140
|
#
|
141
141
|
# The optional `timeout` and `exception` parameters allow to override the
|
142
142
|
# `connect_timeout` and `connect_timeout_error` values.
|
143
143
|
#
|
144
|
-
# @param address [Address, String, Addrinfo, Integer] the address
|
145
|
-
#
|
144
|
+
# @param address [Address, String, Addrinfo, Integer] the target address see
|
145
|
+
# {Address#initialize} for valid formats
|
146
146
|
# @param configuration [Configuration] the {Configuration} to be used for
|
147
147
|
# this instance
|
148
148
|
# @param timeout [Numeric] maximum time in seconds to connect
|
149
|
-
# @param exception [Class] exception class to be used when the
|
150
|
-
# reached
|
149
|
+
# @param exception [Class<Exception>] exception class to be used when the
|
150
|
+
# connect timeout reached
|
151
151
|
#
|
152
152
|
# @return [self]
|
153
153
|
#
|
@@ -165,7 +165,7 @@ class TCPClient
|
|
165
165
|
end
|
166
166
|
|
167
167
|
#
|
168
|
-
#
|
168
|
+
# Flushes all internal buffers (write all through).
|
169
169
|
#
|
170
170
|
# @return [self]
|
171
171
|
#
|
@@ -182,8 +182,8 @@ class TCPClient
|
|
182
182
|
#
|
183
183
|
# @param nbytes [Integer] the number of bytes to read
|
184
184
|
# @param timeout [Numeric] maximum time in seconds to read
|
185
|
-
# @param exception [Class] exception class to be used when the
|
186
|
-
# reached
|
185
|
+
# @param exception [Class<Exception>] exception class to be used when the
|
186
|
+
# read timeout reached
|
187
187
|
#
|
188
188
|
# @return [String] the read buffer
|
189
189
|
#
|
@@ -211,7 +211,7 @@ class TCPClient
|
|
211
211
|
end
|
212
212
|
|
213
213
|
#
|
214
|
-
#
|
214
|
+
# Executes a block with a given overall time limit.
|
215
215
|
#
|
216
216
|
# When you like to ensure that a complete {#read}/{#write} communication
|
217
217
|
# sequence with the server is finished before a given amount of time you use
|
@@ -228,7 +228,6 @@ class TCPClient
|
|
228
228
|
# {#write} calls within the block
|
229
229
|
#
|
230
230
|
# @yieldparam client [TCPClient] self
|
231
|
-
# @yieldreturn [Object] any result
|
232
231
|
#
|
233
232
|
# @return [Object] the block`s result
|
234
233
|
#
|
@@ -245,16 +244,16 @@ class TCPClient
|
|
245
244
|
end
|
246
245
|
|
247
246
|
#
|
248
|
-
#
|
247
|
+
# Writes the given `messages` to the server.
|
249
248
|
#
|
250
249
|
# The optional `timeout` and `exception` parameters allow to override the
|
251
250
|
# `write_timeout` and `write_timeout_error` values of the used
|
252
251
|
# {#configuration}.
|
253
252
|
#
|
254
|
-
# @param messages [String] one or more messages to write
|
253
|
+
# @param messages [Array<String>] one or more messages to write
|
255
254
|
# @param timeout [Numeric] maximum time in seconds to write
|
256
|
-
# @param exception [Class] exception class to be used when the
|
257
|
-
# reached
|
255
|
+
# @param exception [Class<Exception>] exception class to be used when the
|
256
|
+
# write timeout reached
|
258
257
|
#
|
259
258
|
# @return [Integer] bytes written
|
260
259
|
#
|
@@ -9,8 +9,8 @@ RSpec.describe TCPClient::Address do
|
|
9
9
|
|
10
10
|
it 'points to the given port on localhost' do
|
11
11
|
expect(address.hostname).to eq 'localhost'
|
12
|
+
expect(address.port).to be 42
|
12
13
|
expect(address.to_s).to eq 'localhost:42'
|
13
|
-
expect(address.addrinfo.ip_port).to be 42
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'uses IPv6' do
|
@@ -29,8 +29,9 @@ RSpec.describe TCPClient::Address do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'points to the given host and port' do
|
32
|
-
expect(address.hostname).to eq
|
33
|
-
expect(address.
|
32
|
+
expect(address.hostname).to eq 'localhost'
|
33
|
+
expect(address.port).to be 42
|
34
|
+
expect(address.to_s).to eq 'localhost:42'
|
34
35
|
end
|
35
36
|
|
36
37
|
it 'uses IPv6' do
|
@@ -46,30 +47,21 @@ RSpec.describe TCPClient::Address do
|
|
46
47
|
|
47
48
|
it 'points to the given host and port' do
|
48
49
|
expect(address.hostname).to eq 'localhost'
|
50
|
+
expect(address.port).to be 42
|
49
51
|
expect(address.to_s).to eq 'localhost:42'
|
50
|
-
expect(address.addrinfo.ip_port).to be 42
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'uses IPv6' do
|
54
52
|
expect(address.addrinfo.ip?).to be true
|
55
|
-
expect(address.addrinfo.ipv6?).to be true
|
56
|
-
expect(address.addrinfo.ipv4?).to be false
|
57
53
|
end
|
54
|
+
|
58
55
|
end
|
59
56
|
|
60
57
|
context 'when only a port is provided' do
|
61
|
-
subject(:address) { TCPClient::Address.new(':
|
58
|
+
subject(:address) { TCPClient::Address.new(':42') }
|
62
59
|
|
63
60
|
it 'points to the given port on localhost' do
|
64
|
-
expect(address.hostname).to eq ''
|
65
|
-
expect(address.
|
66
|
-
expect(address.
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'uses IPv4' do
|
61
|
+
expect(address.hostname).to eq 'localhost'
|
62
|
+
expect(address.port).to be 42
|
63
|
+
expect(address.to_s).to eq 'localhost:42'
|
70
64
|
expect(address.addrinfo.ip?).to be true
|
71
|
-
expect(address.addrinfo.ipv6?).to be false
|
72
|
-
expect(address.addrinfo.ipv4?).to be true
|
73
65
|
end
|
74
66
|
end
|
75
67
|
|
@@ -78,14 +70,9 @@ RSpec.describe TCPClient::Address do
|
|
78
70
|
|
79
71
|
it 'points to the given port on localhost' do
|
80
72
|
expect(address.hostname).to eq '::1'
|
73
|
+
expect(address.port).to be 42
|
81
74
|
expect(address.to_s).to eq '[::1]:42'
|
82
|
-
expect(address.addrinfo.ip_port).to be 42
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'uses IPv6' do
|
86
75
|
expect(address.addrinfo.ip?).to be true
|
87
|
-
expect(address.addrinfo.ipv6?).to be true
|
88
|
-
expect(address.addrinfo.ipv4?).to be false
|
89
76
|
end
|
90
77
|
end
|
91
78
|
end
|
@@ -108,13 +95,13 @@ RSpec.describe TCPClient::Address do
|
|
108
95
|
expect(address_a).to eq address_b
|
109
96
|
end
|
110
97
|
|
111
|
-
context 'using the ==
|
98
|
+
context 'using the == operator' do
|
112
99
|
it 'compares to equal' do
|
113
100
|
expect(address_a == address_b).to be true
|
114
101
|
end
|
115
102
|
end
|
116
103
|
|
117
|
-
context 'using the ===
|
104
|
+
context 'using the === operator' do
|
118
105
|
it 'compares to equal' do
|
119
106
|
expect(address_a === address_b).to be true
|
120
107
|
end
|
@@ -129,13 +116,13 @@ RSpec.describe TCPClient::Address do
|
|
129
116
|
expect(address_a).not_to eq address_b
|
130
117
|
end
|
131
118
|
|
132
|
-
context 'using the ==
|
119
|
+
context 'using the == operator' do
|
133
120
|
it 'compares not to equal' do
|
134
121
|
expect(address_a == address_b).to be false
|
135
122
|
end
|
136
123
|
end
|
137
124
|
|
138
|
-
context 'using the ===
|
125
|
+
context 'using the === operator' do
|
139
126
|
it 'compares not to equal' do
|
140
127
|
expect(address_a === address_b).to be false
|
141
128
|
end
|
@@ -233,13 +233,13 @@ RSpec.describe TCPClient::Configuration do
|
|
233
233
|
expect(config_a).to eq config_b
|
234
234
|
end
|
235
235
|
|
236
|
-
context 'using the ==
|
236
|
+
context 'using the == operator' do
|
237
237
|
it 'compares to equal' do
|
238
238
|
expect(config_a == config_b).to be true
|
239
239
|
end
|
240
240
|
end
|
241
241
|
|
242
|
-
context 'using the ===
|
242
|
+
context 'using the === operator' do
|
243
243
|
it 'compares to equal' do
|
244
244
|
expect(config_a === config_b).to be true
|
245
245
|
end
|
@@ -254,13 +254,13 @@ RSpec.describe TCPClient::Configuration do
|
|
254
254
|
expect(config_a).not_to eq config_b
|
255
255
|
end
|
256
256
|
|
257
|
-
context 'using the ==
|
257
|
+
context 'using the == operator' do
|
258
258
|
it 'compares not to equal' do
|
259
259
|
expect(config_a == config_b).to be false
|
260
260
|
end
|
261
261
|
end
|
262
262
|
|
263
|
-
context 'using the ===
|
263
|
+
context 'using the === operator' do
|
264
264
|
it 'compares not to equal' do
|
265
265
|
expect(config_a === config_b).to be false
|
266
266
|
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.9.
|
4
|
+
version: 0.9.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: 2021-12-
|
11
|
+
date: 2021-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|