Skip to content

Commit

Permalink
AVRO-516. Ruby socket RPC should use big endian buffer lengths. merge…
Browse files Browse the repository at this point in the history
… from trunk

git-svn-id: https://svn.apache.org/repos/asf/avro/branches/branch-1.3@951276 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Jeff Hodges committed Jun 4, 2010
1 parent 98a1cab commit 0006247
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
8 changes: 8 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ Avro 1.3.3 (Unreleased)

AVRO-450. HTTP IPC for ruby. (jmhodges)

AVRO-508. Use page-backed buffers for C++ serialization input or
output. (sbanacho)

AVRO-516. Removing unnecessary ruby StringIO calls. (jmhodges)

AVRO-516. Ruby socket RPC should use big endian buffer lengths.
(jmhodges)

BUG FIXES
AVRO-461. Skipping primitives in the ruby side (jmhodges)

Expand Down
7 changes: 3 additions & 4 deletions lang/ruby/lib/avro/ipc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,7 @@ def initialize(local_protocol)
# Called by a server to deserialize a request, compute and serialize
# a response or error. Compare to 'handle()' in Thrift.
def respond(call_request)
buffer_reader = StringIO.new(call_request)
buffer_decoder = Avro::IO::BinaryDecoder.new(StringIO.new(call_request))
buffer_decoder = Avro::IO::BinaryDecoder.new(call_request)
buffer_writer = StringIO.new('', 'w+')
buffer_encoder = Avro::IO::BinaryEncoder.new(buffer_writer)
error = nil
Expand Down Expand Up @@ -422,7 +421,7 @@ def write_buffer(chunk)
end

def write_buffer_length(n)
bytes_sent = sock.write([n].pack('I'))
bytes_sent = sock.write([n].pack('N'))
if bytes_sent == 0
raise ConnectionClosedException.new("socket sent 0 bytes")
end
Expand All @@ -433,7 +432,7 @@ def read_buffer_length
if read == '' || read == nil
raise ConnectionClosedException.new("Socket read 0 bytes.")
end
read.unpack('I')[0]
read.unpack('N')[0]
end

def close
Expand Down
5 changes: 2 additions & 3 deletions lang/ruby/test/sample_ipc_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ def make_requestor(server_address, port, protocol)
'body' => ARGV[2]
}

num_messages = ARGV[3].to_i
num_message = 1 if num_messages == 0
num_messages = (ARGV[3] || 1).to_i

# build the parameters for the request
params = {'message' => message}
Expand All @@ -83,4 +82,4 @@ def make_requestor(server_address, port, protocol)
requestor = make_requestor('localhost', 9090, MAIL_PROTOCOL)
result = requestor.request('replay', {})
puts("Replay Result: " + result)
end
end
5 changes: 3 additions & 2 deletions lang/ruby/test/sample_ipc_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ class MailHandler < RequestHandler
def handle(request)
responder = MailResponder.new()
transport = Avro::IPC::SocketTransport.new(request)
transport.write_framed_message(responder.respond(transport))
str = StringIO.new(transport.read_framed_message)
transport.write_framed_message(responder.respond(str))
end
end

if $0 == __FILE__
handler = MailHandler.new('localhost', 9090)
handler.run
end
end
24 changes: 24 additions & 0 deletions lang/ruby/test/test_socket_transport.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'test_help'

class TestSocketTransport < Test::Unit::TestCase
def test_buffer_writing
io = StringIO.new
st = Avro::IPC::SocketTransport.new(io)
buffer_length = "\000\000\000\006" # 6 in big-endian
message = 'abcdef'
null_ending = "\000\000\000\000" # 0 in big-endian
full = buffer_length + message + null_ending
st.write_framed_message('abcdef')
assert_equal full, io.string
end

def test_buffer_reading
buffer_length = "\000\000\000\005" # 5 in big-endian
message = "hello"
null_ending = "\000\000\000\000" # 0 in big-endian
full = buffer_length + message + null_ending
io = StringIO.new(full)
st = Avro::IPC::SocketTransport.new(io)
assert_equal 'hello', st.read_framed_message
end
end

0 comments on commit 0006247

Please sign in to comment.