bertrpc 1.1.2 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/VERSION +1 -1
- data/bertrpc.gemspec +2 -2
- data/lib/bertrpc/action.rb +19 -4
- data/lib/bertrpc/errors.rb +2 -0
- data/test/action_test.rb +6 -6
- metadata +2 -2
data/History.txt
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
data/bertrpc.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bertrpc}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Tom Preston-Werner"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-02-09}
|
13
13
|
s.email = %q{tom@mojombo.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
data/lib/bertrpc/action.rb
CHANGED
@@ -23,8 +23,21 @@ module BERTRPC
|
|
23
23
|
sock.write(bert)
|
24
24
|
end
|
25
25
|
|
26
|
+
def read(sock, len, timeout)
|
27
|
+
data, size = [], 0
|
28
|
+
while size < len
|
29
|
+
r, w, e = IO.select([sock], [], [], timeout)
|
30
|
+
raise Errno::EAGAIN if r.nil?
|
31
|
+
msg, sender = sock.recvfrom(len - size)
|
32
|
+
size += msg.size
|
33
|
+
data << msg
|
34
|
+
end
|
35
|
+
data.join ''
|
36
|
+
end
|
37
|
+
|
26
38
|
def transaction(bert_request)
|
27
|
-
|
39
|
+
timeout = @svc.timeout && Float(@svc.timeout)
|
40
|
+
sock = connect_to(@svc.host, @svc.port, timeout)
|
28
41
|
|
29
42
|
if @req.options
|
30
43
|
if @req.options[:cache] && @req.options[:cache][0] == :validation
|
@@ -35,10 +48,10 @@ module BERTRPC
|
|
35
48
|
end
|
36
49
|
|
37
50
|
write(sock, bert_request)
|
38
|
-
lenheader =
|
51
|
+
lenheader = read(sock, 4, timeout)
|
39
52
|
raise ProtocolError.new(ProtocolError::NO_HEADER) unless lenheader
|
40
53
|
len = lenheader.unpack('N').first
|
41
|
-
bert_response =
|
54
|
+
bert_response = read(sock, len, timeout)
|
42
55
|
raise ProtocolError.new(ProtocolError::NO_DATA) unless bert_response
|
43
56
|
sock.close
|
44
57
|
bert_response
|
@@ -57,7 +70,8 @@ module BERTRPC
|
|
57
70
|
# +port+ Integer port of the target TCP server
|
58
71
|
# +timeout+ Optional Integer (in seconds) of the read timeout
|
59
72
|
def connect_to(host, port, timeout = nil)
|
60
|
-
|
73
|
+
addr = Socket.getaddrinfo(host, nil)
|
74
|
+
sock = Socket.new(Socket.const_get(addr[0][0]), Socket::SOCK_STREAM, 0)
|
61
75
|
sock.setsockopt Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1
|
62
76
|
|
63
77
|
if timeout
|
@@ -68,6 +82,7 @@ module BERTRPC
|
|
68
82
|
sock.setsockopt Socket::SOL_SOCKET, Socket::SO_SNDTIMEO, optval
|
69
83
|
end
|
70
84
|
|
85
|
+
sock.connect(Socket.pack_sockaddr_in(port, addr[0][3]))
|
71
86
|
sock
|
72
87
|
end
|
73
88
|
end
|
data/lib/bertrpc/errors.rb
CHANGED
data/test/action_test.rb
CHANGED
@@ -54,8 +54,8 @@ class ActionTest < Test::Unit::TestCase
|
|
54
54
|
io = stub()
|
55
55
|
io.expects(:write).with("\000\000\000\003")
|
56
56
|
io.expects(:write).with("foo")
|
57
|
-
|
58
|
-
|
57
|
+
@call.expects(:read).with(io, 4, nil).returns("\000\000\000\003")
|
58
|
+
@call.expects(:read).with(io, 3, nil).returns("bar")
|
59
59
|
io.expects(:close)
|
60
60
|
@call.expects(:connect_to).returns(io)
|
61
61
|
assert_equal "bar", @call.transaction("foo")
|
@@ -65,7 +65,7 @@ class ActionTest < Test::Unit::TestCase
|
|
65
65
|
io = stub()
|
66
66
|
io.expects(:write).with("\000\000\000\003")
|
67
67
|
io.expects(:write).with("foo")
|
68
|
-
|
68
|
+
@call.expects(:read).with(io, 4, nil).returns(nil)
|
69
69
|
@call.expects(:connect_to).returns(io)
|
70
70
|
begin
|
71
71
|
@call.transaction("foo")
|
@@ -79,8 +79,8 @@ class ActionTest < Test::Unit::TestCase
|
|
79
79
|
io = stub()
|
80
80
|
io.expects(:write).with("\000\000\000\003")
|
81
81
|
io.expects(:write).with("foo")
|
82
|
-
|
83
|
-
|
82
|
+
@call.expects(:read).with(io, 4, nil).returns("\000\000\000\003")
|
83
|
+
@call.expects(:read).with(io, 3, nil).returns(nil)
|
84
84
|
@call.expects(:connect_to).returns(io)
|
85
85
|
begin
|
86
86
|
@call.transaction("foo")
|
@@ -94,7 +94,7 @@ class ActionTest < Test::Unit::TestCase
|
|
94
94
|
io = stub()
|
95
95
|
io.expects(:write).with("\000\000\000\003")
|
96
96
|
io.expects(:write).with("foo")
|
97
|
-
|
97
|
+
@call.expects(:read).with(io, 4, nil).raises(Errno::EAGAIN)
|
98
98
|
@call.expects(:connect_to).returns(io)
|
99
99
|
begin
|
100
100
|
@call.transaction("foo")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bertrpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Preston-Werner
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-02-09 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|