Set TCP_NODELAY option on the TCPSocket

* Fixes slowness issues on Linux
This commit is contained in:
Benjamin R. Haskell 2012-07-16 10:52:10 -04:00 committed by Joe Ferris
parent da93136a9c
commit 943db0475e
2 changed files with 13 additions and 0 deletions

View File

@ -112,6 +112,9 @@ module Capybara::Webkit
def attempt_connect
@socket = @socket_class.open("127.0.0.1", @port)
if @socket.kind_of?(TCPSocket) and defined?(Socket::TCP_NODELAY)
@socket.setsockopt(:IPPROTO_TCP, :TCP_NODELAY, 1)
end
rescue Errno::ECONNREFUSED
end
end

View File

@ -34,6 +34,16 @@ describe Capybara::Webkit::Connection do
connection.port.should be_between 0x400, 0xffff
end
it 'sets appropriate options on its socket' do
if defined?(Socket::TCP_NODELAY)
args = [:IPPROTO_TCP, :TCP_NODELAY, 1]
TCPSocket.any_instance.should_receive(:setsockopt).with(*args)
else
TCPSocket.any_instance.should_not_receive(:setsockopt)
end
Capybara::Webkit::Connection.new
end
it "chooses a new port number for a new connection" do
new_connection = Capybara::Webkit::Connection.new
new_connection.port.should_not == connection.port