From: Kevin Clark Date: Thu, 26 Jun 2008 18:10:56 +0000 (+0000) Subject: rb: BufferedTransport should flush on close [THRIFT-49] X-Git-Tag: 0.2.0~495 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=091fa95233d793e10a95ebcce9e12b135301a855;p=common%2Fthrift.git rb: BufferedTransport should flush on close [THRIFT-49] This also adds code and spec so nothing will be written to the transport if there's nothing in the write buffer. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@671967 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/lib/rb/lib/thrift/transport.rb b/lib/rb/lib/thrift/transport.rb index 3ea6ee08..36492dd7 100644 --- a/lib/rb/lib/thrift/transport.rb +++ b/lib/rb/lib/thrift/transport.rb @@ -90,6 +90,7 @@ module Thrift end def close + flush @transport.close end @@ -102,9 +103,12 @@ module Thrift end def flush - @transport.write(@wbuf) + if @wbuf != '' + @transport.write(@wbuf) + @wbuf = '' + end + @transport.flush - @wbuf = '' end end deprecate_class! :TBufferedTransport => BufferedTransport diff --git a/lib/rb/spec/transport_spec.rb b/lib/rb/spec/transport_spec.rb index 5d5c92f7..44d0508a 100644 --- a/lib/rb/spec/transport_spec.rb +++ b/lib/rb/spec/transport_spec.rb @@ -52,6 +52,7 @@ class ThriftTransportSpec < Spec::ExampleGroup trans = mock("Transport") trans.should_receive(:open?).ordered.and_return("+ open?") trans.should_receive(:open).ordered.and_return("+ open") + trans.should_receive(:flush).ordered # from the close trans.should_receive(:close).ordered.and_return("+ close") trans.should_receive(:read).with(217).ordered.and_return("+ read") btrans = BufferedTransport.new(trans) @@ -81,7 +82,22 @@ class ThriftTransportSpec < Spec::ExampleGroup trans.should_receive(:write).with("one/two/three/") trans.stub!(:flush) btrans.flush - trans.should_receive(:write).with("") + # Nothing to flush with no data + btrans.flush + end + + it "should flush on close" do + trans = mock("Transport") + trans.should_receive(:close) + btrans = BufferedTransport.new(trans) + btrans.should_receive(:flush) + btrans.close + end + + it "should not write to socket if there's no data" do + trans = mock("Transport") + trans.should_receive(:flush) + btrans = BufferedTransport.new(trans) btrans.flush end end