protoplasm-blocking-client 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,7 +17,23 @@ module Protoplasm
17
17
 
18
18
  def _socket
19
19
  host, port = host_port
20
- @_socket ||= TCPSocket.open(host, port)
20
+ count = 0
21
+ begin
22
+ @socket ||= begin
23
+ s = TCPSocket.open(host, port)
24
+ s.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true)
25
+ s
26
+ end
27
+ yield @socket
28
+ rescue Errno::EPIPE, Errno::ECONNRESET
29
+ count += 1
30
+ if count > 3
31
+ raise
32
+ else
33
+ @socket = nil
34
+ retry
35
+ end
36
+ end
21
37
  end
22
38
 
23
39
  def send_request(field, *args, &blk)
@@ -26,30 +42,31 @@ module Protoplasm
26
42
  cmd_class = type.command_class.fields.values.find{|f| f.name == field}
27
43
  cmd = self.class._types.request_class.new(self.class._types.request_type_field => type.type, type.field => cmd_class.type.new(*args))
28
44
  cmd.encode(s)
29
- socket = _socket
30
- socket.write([Types::Request::NORMAL, s.size].pack("CQ"))
31
- socket.write s
32
- socket.flush
33
- fetch_objects = true
34
45
  obj = nil
35
- while fetch_objects
36
- response_byte = socket.read(1)
37
- response_code = response_byte.unpack("C").first
38
- case response_code
39
- when Types::Response::NORMAL
40
- fetch_objects = !type.void?
41
- if fetch_objects
42
- len_buf = socket.read(8)
43
- len = len_buf.unpack("Q").first
44
- data = socket.read(len)
45
- obj = type.response_class.decode(data)
46
- yield obj if block_given?
46
+ _socket do |socket|
47
+ socket.write([Types::Request::NORMAL, s.size].pack("CQ"))
48
+ socket.write s
49
+ socket.flush
50
+ fetch_objects = true
51
+ while fetch_objects
52
+ response_byte = socket.read(1)
53
+ response_code = response_byte.unpack("C").first
54
+ case response_code
55
+ when Types::Response::NORMAL
56
+ fetch_objects = !type.void?
57
+ if fetch_objects
58
+ len_buf = socket.read(8)
59
+ len = len_buf.unpack("Q").first
60
+ data = socket.read(len)
61
+ obj = type.response_class.decode(data)
62
+ yield obj if block_given?
63
+ end
64
+ fetch_objects = false unless type.streaming?
65
+ when Types::Response::STOP_STREAMING
66
+ fetch_objects = false
67
+ else
68
+ raise "Control byte is #{response_byte.inspect}, code is #{response_code.inspect}"
47
69
  end
48
- fetch_objects = false unless type.streaming?
49
- when Types::Response::STOP_STREAMING
50
- fetch_objects = false
51
- else
52
- raise "Control byte is #{response_byte.inspect}, code is #{response_code.inspect}"
53
70
  end
54
71
  end
55
72
  obj
@@ -1,3 +1,3 @@
1
1
  module Protoplasm
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,56 +1,78 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: protoplasm-blocking-client
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.2
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 3
10
+ version: 0.1.3
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Josh Hull
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-01-04 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: beefcake
16
- requirement: &70224617142360 !ruby/object:Gem::Requirement
17
+
18
+ date: 2012-01-10 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
17
22
  none: false
18
- requirements:
23
+ requirements:
19
24
  - - ~>
20
- - !ruby/object:Gem::Version
25
+ - !ruby/object:Gem::Version
26
+ hash: 29
27
+ segments:
28
+ - 0
29
+ - 3
30
+ - 7
21
31
  version: 0.3.7
32
+ requirement: *id001
22
33
  type: :runtime
23
34
  prerelease: false
24
- version_requirements: *70224617142360
25
- - !ruby/object:Gem::Dependency
26
- name: rake
27
- requirement: &70224617141940 !ruby/object:Gem::Requirement
35
+ name: beefcake
36
+ - !ruby/object:Gem::Dependency
37
+ version_requirements: &id002 !ruby/object:Gem::Requirement
28
38
  none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ requirement: *id002
33
47
  type: :development
34
48
  prerelease: false
35
- version_requirements: *70224617141940
36
- - !ruby/object:Gem::Dependency
37
- name: minitest
38
- requirement: &70224617141400 !ruby/object:Gem::Requirement
49
+ name: rake
50
+ - !ruby/object:Gem::Dependency
51
+ version_requirements: &id003 !ruby/object:Gem::Requirement
39
52
  none: false
40
- requirements:
53
+ requirements:
41
54
  - - ~>
42
- - !ruby/object:Gem::Version
55
+ - !ruby/object:Gem::Version
56
+ hash: 21
57
+ segments:
58
+ - 2
59
+ - 6
60
+ - 1
43
61
  version: 2.6.1
62
+ requirement: *id003
44
63
  type: :development
45
64
  prerelease: false
46
- version_requirements: *70224617141400
65
+ name: minitest
47
66
  description: A blocking client for a Protoplasm server.
48
- email:
67
+ email:
49
68
  - joshbuddy@gmail.com
50
69
  executables: []
70
+
51
71
  extensions: []
72
+
52
73
  extra_rdoc_files: []
53
- files:
74
+
75
+ files:
54
76
  - .gitignore
55
77
  - Gemfile
56
78
  - README.md
@@ -66,34 +88,37 @@ files:
66
88
  - test/test_helper.rb
67
89
  homepage: https://github.com/bazaarlabs/protoplasm
68
90
  licenses: []
91
+
69
92
  post_install_message:
70
93
  rdoc_options: []
71
- require_paths:
94
+
95
+ require_paths:
72
96
  - lib
73
- required_ruby_version: !ruby/object:Gem::Requirement
97
+ required_ruby_version: !ruby/object:Gem::Requirement
74
98
  none: false
75
- requirements:
76
- - - ! '>='
77
- - !ruby/object:Gem::Version
78
- version: '0'
79
- segments:
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
80
104
  - 0
81
- hash: 4090923455675816360
82
- required_rubygems_version: !ruby/object:Gem::Requirement
105
+ version: "0"
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
107
  none: false
84
- requirements:
85
- - - ! '>='
86
- - !ruby/object:Gem::Version
87
- version: '0'
88
- segments:
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ hash: 3
112
+ segments:
89
113
  - 0
90
- hash: 4090923455675816360
114
+ version: "0"
91
115
  requirements: []
116
+
92
117
  rubyforge_project: protoplasm-blocking-client
93
118
  rubygems_version: 1.8.10
94
119
  signing_key:
95
120
  specification_version: 3
96
121
  summary: A blocking client for a Protoplasm server
97
- test_files:
122
+ test_files:
98
123
  - test/protoplasm_test.rb
99
124
  - test/test_helper.rb