jrpc 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jrpc/transport/socket_base.rb +6 -0
- data/lib/jrpc/transport/socket_tcp.rb +24 -15
- data/lib/jrpc/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb8407031cb5fb20510c28a5691cff0bc10d787e
|
4
|
+
data.tar.gz: acc04f635eca963b97e17dc64ef3b91cb2235151
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a60569920b9c4f2cd70b2c5f75106f9b34ffe1ac6bd56e35bd22cefa93c81a1f2920994c79557158ef127d9e1675f8f84c447df262a5ac728c002b386b36dcd
|
7
|
+
data.tar.gz: 4d79982ababcd0b15d888f25212751f8c0908b333fab3d8622c315dac260373735a842a710ac96fa957ef6763dff029008121ab9e8abe29a1d6c2486cfe2018a
|
@@ -2,49 +2,59 @@ module JRPC
|
|
2
2
|
module Transport
|
3
3
|
class SocketTcp < SocketBase
|
4
4
|
|
5
|
-
attr_reader :socket
|
6
|
-
|
7
|
-
def initialize(options)
|
8
|
-
super
|
9
|
-
@socket = build_socket
|
10
|
-
end
|
11
|
-
|
12
5
|
def read(length, timeout = @read_timeout)
|
13
6
|
received = ''
|
14
7
|
length_to_read = length
|
15
8
|
while length_to_read > 0
|
16
|
-
io_read, = IO.select([
|
9
|
+
io_read, = IO.select([socket], [], [], timeout)
|
17
10
|
raise ReadTimeoutError unless io_read
|
18
11
|
chunk = io_read[0].read_nonblock(length_to_read)
|
19
12
|
received += chunk
|
20
13
|
length_to_read -= chunk.bytesize
|
21
14
|
end
|
22
15
|
received
|
16
|
+
rescue Errno::EPIPE => e
|
17
|
+
# EPIPE, in this case, means that the data connection was unexpectedly terminated.
|
18
|
+
clear_socket!
|
19
|
+
raise ReadFailedError, "#{e.class} #{e.message}"
|
23
20
|
end
|
24
21
|
|
25
22
|
def write(data, timeout = @write_timeout)
|
26
23
|
length_written = 0
|
27
24
|
data_to_write = data
|
28
25
|
while data_to_write.bytesize > 0
|
29
|
-
_, io_write, = IO.select([], [
|
26
|
+
_, io_write, = IO.select([], [socket], [], timeout)
|
30
27
|
raise WriteTimeoutError unless io_write
|
31
28
|
chunk_length = io_write[0].write_nonblock(data_to_write)
|
32
29
|
length_written += chunk_length
|
33
30
|
data_to_write = data.byteslice(length_written, data.length)
|
34
31
|
end
|
35
32
|
length_written
|
33
|
+
rescue Errno::EPIPE => e
|
34
|
+
# EPIPE, in this case, means that the data connection was unexpectedly terminated.
|
35
|
+
clear_socket!
|
36
|
+
raise WriteFailedError, "#{e.class} #{e.message}"
|
36
37
|
end
|
37
38
|
|
38
39
|
def close
|
39
|
-
@socket.
|
40
|
+
return if @socket.nil?
|
41
|
+
socket.close
|
40
42
|
end
|
41
43
|
|
42
44
|
def closed?
|
43
|
-
@socket.closed?
|
45
|
+
@socket.nil? || socket.closed?
|
46
|
+
end
|
47
|
+
|
48
|
+
def socket
|
49
|
+
@socket ||= build_socket
|
44
50
|
end
|
45
51
|
|
46
52
|
private
|
47
53
|
|
54
|
+
def clear_socket!
|
55
|
+
@socket = nil
|
56
|
+
end
|
57
|
+
|
48
58
|
def set_timeout_to(socket, type, value)
|
49
59
|
secs = Integer(value)
|
50
60
|
u_secs = Integer((value - secs) * 1_000_000)
|
@@ -64,12 +74,11 @@ module JRPC
|
|
64
74
|
host, port = @server.split(':')
|
65
75
|
addr = Socket.getaddrinfo(host, nil)
|
66
76
|
full_addr = Socket.pack_sockaddr_in(port, addr[0][3])
|
67
|
-
|
77
|
+
socket.connect(full_addr)
|
68
78
|
rescue Errno::EISCONN => _
|
69
79
|
# already connected
|
70
|
-
rescue Errno::ETIMEDOUT =>
|
71
|
-
|
72
|
-
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ETIMEDOUT => e
|
80
|
+
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ETIMEDOUT, Errno::EPIPE => e
|
81
|
+
clear_socket!
|
73
82
|
raise ConnectionFailedError, "#{e.class} #{e.message}"
|
74
83
|
end
|
75
84
|
|
data/lib/jrpc/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jrpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Talakevich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: netstring
|