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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b8980207596bc025bf5c28fd37efc498d8f3bb6a
4
- data.tar.gz: c29420bd1ae1698195b7dbe065f10410338852f1
3
+ metadata.gz: fb8407031cb5fb20510c28a5691cff0bc10d787e
4
+ data.tar.gz: acc04f635eca963b97e17dc64ef3b91cb2235151
5
5
  SHA512:
6
- metadata.gz: f66a01cc18c2897929fed709bb8f1f1cd904a709de5313f7175a8f7263488598d3f24366bc2234c68c81d8a93fa6b1ac04744be85390bc93c8fba6967b2d9412
7
- data.tar.gz: e7d3229d00028b99a75baf5c4d23136751987362dd841ccc5147523d9bad8de4dc121ad26c8213a30dc02a620df9518fef8241cabbaeacab3ef9f2ce8e092b06
6
+ metadata.gz: 4a60569920b9c4f2cd70b2c5f75106f9b34ffe1ac6bd56e35bd22cefa93c81a1f2920994c79557158ef127d9e1675f8f84c447df262a5ac728c002b386b36dcd
7
+ data.tar.gz: 4d79982ababcd0b15d888f25212751f8c0908b333fab3d8622c315dac260373735a842a710ac96fa957ef6763dff029008121ab9e8abe29a1d6c2486cfe2018a
@@ -23,6 +23,12 @@ module JRPC
23
23
  class ConnectionFailedError < Error
24
24
  end
25
25
 
26
+ class WriteFailedError < Error
27
+ end
28
+
29
+ class ReadFailedError < Error
30
+ end
31
+
26
32
  attr_reader :options, :read_timeout, :write_timeout
27
33
 
28
34
  def self.connect(options)
@@ -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([@socket], [], [], timeout)
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([], [@socket], [], timeout)
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.close
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
- @socket.connect(full_addr)
77
+ socket.connect(full_addr)
68
78
  rescue Errno::EISCONN => _
69
79
  # already connected
70
- rescue Errno::ETIMEDOUT => _
71
- raise ConnectionTimeoutError
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
 
@@ -1,3 +1,3 @@
1
1
  module JRPC
2
- VERSION = '1.1.1'
2
+ VERSION = '1.1.2'
3
3
  end
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.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-07-27 00:00:00.000000000 Z
11
+ date: 2018-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: netstring