bertclient 0.1 → 0.2
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.
- data/lib/bertclient.rb +17 -4
- metadata +11 -5
data/lib/bertclient.rb
CHANGED
@@ -13,13 +13,13 @@ module BERT
|
|
13
13
|
class BadHeader < RPCError; end
|
14
14
|
class BadData < RPCError; end
|
15
15
|
|
16
|
-
def initialize(opts={})
|
16
|
+
def initialize(opts={}, &block)
|
17
17
|
@host = opts[:host] || 'localhost'
|
18
18
|
@port = opts[:port] || 9999
|
19
19
|
@ssl = opts[:ssl] || false
|
20
20
|
@verify_ssl = opts.has_key?(:verify_ssl) ? opts[:verify_ssl] : true
|
21
21
|
@socket = {}
|
22
|
-
|
22
|
+
execute(&block) if block_given?
|
23
23
|
end
|
24
24
|
|
25
25
|
def call(mod, fun, *args)
|
@@ -75,7 +75,7 @@ module BERT
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def socket
|
78
|
-
@socket[Thread.current]
|
78
|
+
@socket[Thread.current] ||= connect
|
79
79
|
end
|
80
80
|
|
81
81
|
# Open socket to service, use SSL if necessary
|
@@ -87,10 +87,23 @@ module BERT
|
|
87
87
|
sock.connect
|
88
88
|
sock.post_connection_check(@host) if @verify_ssl
|
89
89
|
end
|
90
|
-
|
90
|
+
sock
|
91
|
+
end
|
92
|
+
|
93
|
+
# Close socket and clean it up from the pool
|
94
|
+
def close
|
95
|
+
socket.close
|
96
|
+
@socket.delete(Thread.current)
|
91
97
|
true
|
92
98
|
end
|
93
99
|
|
100
|
+
# Accepts a block, yields the client, closes socket at the end of the block
|
101
|
+
def execute
|
102
|
+
ret = yield self
|
103
|
+
close
|
104
|
+
ret
|
105
|
+
end
|
106
|
+
|
94
107
|
# Reads a new berp from the socket and returns the decoded object
|
95
108
|
def read_berp
|
96
109
|
length = socket.read(4).unpack('N')[0]
|
metadata
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bertclient
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 2
|
8
|
+
version: "0.2"
|
5
9
|
platform: ruby
|
6
10
|
authors:
|
7
11
|
- Jared Kuolt
|
@@ -9,7 +13,7 @@ autorequire:
|
|
9
13
|
bindir: bin
|
10
14
|
cert_chain: []
|
11
15
|
|
12
|
-
date: 2010-03-
|
16
|
+
date: 2010-03-24 00:00:00 -07:00
|
13
17
|
default_executable:
|
14
18
|
dependencies: []
|
15
19
|
|
@@ -36,18 +40,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
36
40
|
requirements:
|
37
41
|
- - ">="
|
38
42
|
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 0
|
39
45
|
version: "0"
|
40
|
-
version:
|
41
46
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
47
|
requirements:
|
43
48
|
- - ">="
|
44
49
|
- !ruby/object:Gem::Version
|
50
|
+
segments:
|
51
|
+
- 0
|
45
52
|
version: "0"
|
46
|
-
version:
|
47
53
|
requirements: []
|
48
54
|
|
49
55
|
rubyforge_project: bertclient
|
50
|
-
rubygems_version: 1.3.
|
56
|
+
rubygems_version: 1.3.6
|
51
57
|
signing_key:
|
52
58
|
specification_version: 3
|
53
59
|
summary: A threadsafe BERT-RPC client with ssl support and persistent connections
|