Author: jfarrell
Date: Fri Sep 28 11:25:42 2012
New Revision: 1391399
URL: http://svn.apache.org/viewvc?rev=1391399&view=rev
Log:
THRIFT-1591: Enable TCP_NODELAY for ruby gem
Client: rb
Patch: Christos Trochalakis
Set TCP_NODELAY for client socket for ruby lib
Modified:
thrift/trunk/lib/rb/lib/thrift/transport/socket.rb
thrift/trunk/lib/rb/spec/socket_spec.rb
Modified: thrift/trunk/lib/rb/lib/thrift/transport/socket.rb
URL:
http://svn.apache.org/viewvc/thrift/trunk/lib/rb/lib/thrift/transport/socket.rb?rev=1391399&r1=1391398&r2=1391399&view=diff
==============================================================================
--- thrift/trunk/lib/rb/lib/thrift/transport/socket.rb (original)
+++ thrift/trunk/lib/rb/lib/thrift/transport/socket.rb Fri Sep 28 11:25:42 2012
@@ -36,6 +36,7 @@ module Thrift
begin
addrinfo = ::Socket::getaddrinfo(@host, @port, nil,
::Socket::SOCK_STREAM).first
@handle = ::Socket.new(addrinfo[4], ::Socket::SOCK_STREAM, 0)
+ @handle.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1)
sockaddr = ::Socket.sockaddr_in(addrinfo[1], addrinfo[3])
begin
@handle.connect_nonblock(sockaddr)
Modified: thrift/trunk/lib/rb/spec/socket_spec.rb
URL:
http://svn.apache.org/viewvc/thrift/trunk/lib/rb/spec/socket_spec.rb?rev=1391399&r1=1391398&r2=1391399&view=diff
==============================================================================
--- thrift/trunk/lib/rb/spec/socket_spec.rb (original)
+++ thrift/trunk/lib/rb/spec/socket_spec.rb Fri Sep 28 11:25:42 2012
@@ -28,6 +28,7 @@ describe 'Socket' do
@handle = mock("Handle", :closed? => false)
@handle.stub!(:close)
@handle.stub!(:connect_nonblock)
+ @handle.stub!(:setsockopt)
::Socket.stub!(:new).and_return(@handle)
end
@@ -39,14 +40,14 @@ describe 'Socket' do
end
it "should open a ::Socket with default args" do
- ::Socket.should_receive(:new).and_return(mock("Handle",
:connect_nonblock => true))
+ ::Socket.should_receive(:new).and_return(mock("Handle",
:connect_nonblock => true, :setsockopt => nil))
::Socket.should_receive(:getaddrinfo).with("localhost", 9090, nil,
::Socket::SOCK_STREAM).and_return([[]])
::Socket.should_receive(:sockaddr_in)
@socket.open
end
it "should accept host/port options" do
- ::Socket.should_receive(:new).and_return(mock("Handle",
:connect_nonblock => true))
+ ::Socket.should_receive(:new).and_return(mock("Handle",
:connect_nonblock => true, :setsockopt => nil))
::Socket.should_receive(:getaddrinfo).with("my.domain", 1234, nil,
::Socket::SOCK_STREAM).and_return([[]])
::Socket.should_receive(:sockaddr_in)
Thrift::Socket.new('my.domain', 1234).open