jrpc 0.4.0 → 0.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb7d08dcd06b5a129f1ff83e15fe093da354c038
4
- data.tar.gz: 461277ae63ac277d120d612129a34c64ae70d4d5
3
+ metadata.gz: e89a5ee4a355e8a5e74995a7982fc0489fab9d4a
4
+ data.tar.gz: 8fc4c104259c6940ff17b54de901f76a898876a6
5
5
  SHA512:
6
- metadata.gz: b17f649d6868a52226f0b0854777e68cf87114a99814860ef881970295646a18c97a19e9514fe93a568446c217a145c16e9674b277956cb3571d7a547c5d0976
7
- data.tar.gz: dd952ce1a936fd5b8b9caf02fe04f7b1d2cdda891b8f8dcd9380c4242819a24663a29954b6947dec94999ccb2ef10794e96d169cb4b486e46d158dc280bcf7a2
6
+ metadata.gz: a04e2ae8e0cb1b31132defdf351eb137e58fdadeeae4b2216b7991a9b114443a7474f55d498c9a225a33c7eac646981933429e5643ba0222ba98ed2e05c811d8
7
+ data.tar.gz: 420c095c3f5f76dc3017165301ee46fa8625df6332159163e4069856aeb17e33ec87369d3cdcd33b0635c430cc8a36206e954df9c280c473bb3f772e317b1e1a
@@ -1,7 +1,6 @@
1
1
  require 'jrpc/version'
2
2
  require 'jrpc/base_client'
3
3
  require 'jrpc/tcp_client'
4
- require 'jrpc/safe_tcp_client'
5
4
  require 'jrpc/error/error'
6
5
  require 'jrpc/error/client_error'
7
6
  require 'jrpc/error/server_error'
@@ -3,49 +3,29 @@ require 'netstring'
3
3
  module JRPC
4
4
  class TcpClient < BaseClient
5
5
  attr_reader :namespace
6
- def_delegators :@socket, :logger, :logger=
6
+ def_delegators :@client, :logger, :logger=, :close, :closed?
7
7
 
8
8
  def initialize(uri, options = {})
9
9
  super
10
10
  @namespace = options.delete(:namespace).to_s
11
- connect if options.fetch(:connect_on_initialize, true)
12
- end
11
+ t = @options.fetch(:timeout, 5)
13
12
 
14
- def connect
15
- close if alive?
16
- @socket = Net::TCPClient.new(connection_params)
17
- end
18
-
19
- def close
20
- unless @socket.nil?
21
- @socket.close
22
- @socket = nil
23
- end
24
- end
25
-
26
- def alive?
27
- if @socket.nil?
28
- false
29
- else
30
- @socket.alive?
31
- end
13
+ @client = Net::TCPClient.new server: @uri,
14
+ connect_retry_count: t,
15
+ connect_timeout: t,
16
+ read_timeout: t,
17
+ # write_timeout: t,
18
+ buffered: false # recommended for RPC
32
19
  end
33
20
 
34
21
  private
35
22
 
36
- def connection_params
37
- t = options.fetch(:timeout, 5)
38
- {server: uri, connect_retry_count: t, connect_timeout: t, read_timeout: t, buffered: false}
39
- end
40
-
41
23
  def send_command(request)
42
- connect unless alive?
43
24
  send_request(request)
44
25
  receive_response
45
26
  end
46
27
 
47
28
  def send_notification(request)
48
- connect unless alive?
49
29
  send_request(request)
50
30
  end
51
31
 
@@ -54,12 +34,12 @@ module JRPC
54
34
  end
55
35
 
56
36
  def send_request(request)
57
- @socket.write Netstring.dump(request.to_s)
37
+ @client.write Netstring.dump(request.to_s)
58
38
  end
59
39
 
60
40
  def receive_response
61
41
  length = get_msg_length
62
- response = @socket.read(length+1)
42
+ response = @client.read(length+1)
63
43
  raise ClientError.new('invalid response. missed comma as terminator') if response[-1] != ','
64
44
  response.chomp(',')
65
45
  end
@@ -67,7 +47,7 @@ module JRPC
67
47
  def get_msg_length
68
48
  length = ''
69
49
  while true do
70
- character = @socket.read(1)
50
+ character = @client.read(1)
71
51
  break if character == ':'
72
52
  length += character
73
53
  end
@@ -76,4 +56,4 @@ module JRPC
76
56
  end
77
57
 
78
58
  end
79
- end
59
+ end
@@ -1,3 +1,3 @@
1
1
  module JRPC
2
- VERSION = '0.4.0'
2
+ VERSION = '0.4.1'
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: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Talakevich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-25 00:00:00.000000000 Z
11
+ date: 2015-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: netstring
@@ -107,7 +107,6 @@ files:
107
107
  - lib/jrpc/error/parse_error.rb
108
108
  - lib/jrpc/error/server_error.rb
109
109
  - lib/jrpc/error/unknown_error.rb
110
- - lib/jrpc/safe_tcp_client.rb
111
110
  - lib/jrpc/tcp_client.rb
112
111
  - lib/jrpc/version.rb
113
112
  homepage: https://github.com/senid231/jrpc
@@ -1,25 +0,0 @@
1
- require 'net/tcp_client'
2
- require 'netstring'
3
- module JRPC
4
- class SafeTcpClient < TcpClient
5
-
6
- def initialize(uri, options = {})
7
- super uri, options.merge(connect_on_initialize: false)
8
- end
9
-
10
- private
11
-
12
- def send_command(request)
13
- super
14
- ensure
15
- close
16
- end
17
-
18
- def send_notification(request)
19
- super
20
- ensure
21
- close
22
- end
23
-
24
- end
25
- end