protoplasm-em-server 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,67 +1,92 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: protoplasm-em-server
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: eventmachine
16
- requirement: &70203485248320 !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:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ hash: 3
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ requirement: *id001
22
31
  type: :runtime
23
32
  prerelease: false
24
- version_requirements: *70203485248320
25
- - !ruby/object:Gem::Dependency
26
- name: beefcake
27
- requirement: &70203485183020 !ruby/object:Gem::Requirement
33
+ name: eventmachine
34
+ - !ruby/object:Gem::Dependency
35
+ version_requirements: &id002 !ruby/object:Gem::Requirement
28
36
  none: false
29
- requirements:
37
+ requirements:
30
38
  - - ~>
31
- - !ruby/object:Gem::Version
39
+ - !ruby/object:Gem::Version
40
+ hash: 29
41
+ segments:
42
+ - 0
43
+ - 3
44
+ - 7
32
45
  version: 0.3.7
46
+ requirement: *id002
33
47
  type: :runtime
34
48
  prerelease: false
35
- version_requirements: *70203485183020
36
- - !ruby/object:Gem::Dependency
37
- name: rake
38
- requirement: &70203485180540 !ruby/object:Gem::Requirement
49
+ name: beefcake
50
+ - !ruby/object:Gem::Dependency
51
+ version_requirements: &id003 !ruby/object:Gem::Requirement
39
52
  none: false
40
- requirements:
41
- - - ! '>='
42
- - !ruby/object:Gem::Version
43
- version: '0'
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ requirement: *id003
44
61
  type: :development
45
62
  prerelease: false
46
- version_requirements: *70203485180540
47
- - !ruby/object:Gem::Dependency
48
- name: minitest
49
- requirement: &70203485177180 !ruby/object:Gem::Requirement
63
+ name: rake
64
+ - !ruby/object:Gem::Dependency
65
+ version_requirements: &id004 !ruby/object:Gem::Requirement
50
66
  none: false
51
- requirements:
67
+ requirements:
52
68
  - - ~>
53
- - !ruby/object:Gem::Version
69
+ - !ruby/object:Gem::Version
70
+ hash: 21
71
+ segments:
72
+ - 2
73
+ - 6
74
+ - 1
54
75
  version: 2.6.1
76
+ requirement: *id004
55
77
  type: :development
56
78
  prerelease: false
57
- version_requirements: *70203485177180
79
+ name: minitest
58
80
  description: A protoplasm server backed by EventMachine.
59
- email:
81
+ email:
60
82
  - joshbuddy@gmail.com
61
83
  executables: []
84
+
62
85
  extensions: []
86
+
63
87
  extra_rdoc_files: []
64
- files:
88
+
89
+ files:
65
90
  - .gitignore
66
91
  - Gemfile
67
92
  - README.md
@@ -77,34 +102,37 @@ files:
77
102
  - test/test_helper.rb
78
103
  homepage: https://github.com/bazaarlabs/protoplasm
79
104
  licenses: []
105
+
80
106
  post_install_message:
81
107
  rdoc_options: []
82
- require_paths:
108
+
109
+ require_paths:
83
110
  - lib
84
- required_ruby_version: !ruby/object:Gem::Requirement
111
+ required_ruby_version: !ruby/object:Gem::Requirement
85
112
  none: false
86
- requirements:
87
- - - ! '>='
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- segments:
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ hash: 3
117
+ segments:
91
118
  - 0
92
- hash: 1388192791279370629
93
- required_rubygems_version: !ruby/object:Gem::Requirement
119
+ version: "0"
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
121
  none: false
95
- requirements:
96
- - - ! '>='
97
- - !ruby/object:Gem::Version
98
- version: '0'
99
- segments:
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ hash: 3
126
+ segments:
100
127
  - 0
101
- hash: 1388192791279370629
128
+ version: "0"
102
129
  requirements: []
130
+
103
131
  rubyforge_project: protoplasm-em-server
104
132
  rubygems_version: 1.8.10
105
133
  signing_key:
106
134
  specification_version: 3
107
135
  summary: A protoplasm server backed by EventMachine
108
- test_files:
136
+ test_files:
109
137
  - test/protoplasm_test.rb
110
138
  - test/test_helper.rb