THRIFT-1591: Enable TCP_NODELAY for ruby gem
Client: rb
Patch: Christos Trochalakis

Set TCP_NODELAY for client socket for ruby lib



git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1391399 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/rb/lib/thrift/transport/socket.rb b/lib/rb/lib/thrift/transport/socket.rb
index dfb33fd..36461e9 100644
--- a/lib/rb/lib/thrift/transport/socket.rb
+++ b/lib/rb/lib/thrift/transport/socket.rb
@@ -36,6 +36,7 @@
       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)
diff --git a/lib/rb/spec/socket_spec.rb b/lib/rb/spec/socket_spec.rb
index ef8a0a1..e6b6732 100644
--- a/lib/rb/spec/socket_spec.rb
+++ b/lib/rb/spec/socket_spec.rb
@@ -28,6 +28,7 @@
       @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 @@
     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