Permalink
Browse files

AVRO-1177. Ruby: Fix RPC to only send handshake for first request ove…

…r a connection. Contributed by Georg Franz.

git-svn-id: https://svn.apache.org/repos/asf/avro/trunk@1414979 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 2efa6ce commit fb165e6ec812d4d03ea89de09ca1b758a7cdab6c @cutting cutting committed Nov 28, 2012
Showing with 20 additions and 3 deletions.
  1. +3 −0 CHANGES.txt
  2. +17 −3 lang/ruby/lib/avro/ipc.rb
View
@@ -66,6 +66,9 @@ Trunk (not yet released)
AVRO-1206. Ruby: Fix UTF-8 handling in Ruby 1.9.
(Nicolas Fouché via cutting)
+ AVRO-1177. Ruby: Fix RPC to only send handshake for first request
+ over a connection. (Georg Franz via cutting)
+
Avro 1.7.2 (20 October 2012)
NEW FEATURES
View
@@ -242,15 +242,15 @@ 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)
+ def respond(call_request, transport=nil)
buffer_decoder = Avro::IO::BinaryDecoder.new(StringIO.new(call_request))
buffer_writer = StringIO.new('', 'w+')
buffer_encoder = Avro::IO::BinaryEncoder.new(buffer_writer)
error = nil
response_metadata = {}
begin
- remote_protocol = process_handshake(buffer_decoder, buffer_encoder)
+ remote_protocol = process_handshake(buffer_decoder, buffer_encoder, transport)
# handshake failure
unless remote_protocol
return buffer_writer.string
@@ -302,7 +302,10 @@ def respond(call_request)
buffer_writer.string
end
- def process_handshake(decoder, encoder)
+ def process_handshake(decoder, encoder, connection=nil)
+ if connection && connection.is_connected?
+ return connection.protocol
+ end
handshake_request = HANDSHAKE_RESPONDER_READER.read(decoder)
handshake_response = {}
@@ -338,6 +341,11 @@ def process_handshake(decoder, encoder)
end
HANDSHAKE_RESPONDER_WRITER.write(handshake_response, encoder)
+
+ if connection && handshake_response['match'] != 'NONE'
+ connection.protocol = remote_protocol
+ end
+
remote_protocol
end
@@ -366,9 +374,15 @@ class SocketTransport
# A simple socket-based Transport implementation.
attr_reader :sock, :remote_name
+ attr_accessor :protocol
def initialize(sock)
@sock = sock
+ @protocol = nil
+ end
+
+ def is_connected?()
+ !!@protocol
end
def transceive(request)

0 comments on commit fb165e6

Please sign in to comment.