Skip to content
Browse files

Set TCP_NODELAY option on the TCPSocket

* Fixes slowness issues on Linux
  • Loading branch information...
1 parent da93136 commit 943db0475ebaabf339f8116c9e2b4ebb46c31ce8 @benizi benizi committed with jferris Jul 16, 2012
Showing with 13 additions and 0 deletions.
  1. +3 −0 lib/capybara/webkit/connection.rb
  2. +10 −0 spec/connection_spec.rb
View
3 lib/capybara/webkit/connection.rb
@@ -112,6 +112,9 @@ def connect
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
10 spec/connection_spec.rb
@@ -34,6 +34,16 @@
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

1 comment on commit 943db04

@dwt
dwt commented on 943db04 Oct 5, 2012

This throws a strange error for me:

  Invalid argument (Errno::EINVAL)
  /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/timeout.rb:67:in `timeout'
  ./features/step_definitions/web_steps.rb:31:in `/^(?:|I )go to (.+)$/'
  features/error_handling.feature:7:in `Given I am logged in as "ak@sntl-publishing.com" with password "zms" in the first browser'
  Invalid argument (Errno::EINVAL)
  /Users/dwt/Library/Ruby/Gems/1.8/bundler/gems/capybara-webkit-e39a5c9ef56e/lib/capybara/webkit/connection.rb:116:in `setsockopt'
  /Users/dwt/Library/Ruby/Gems/1.8/bundler/gems/capybara-webkit-e39a5c9ef56e/lib/capybara/webkit/connection.rb:116:in `attempt_connect'
  /Users/dwt/Library/Ruby/Gems/1.8/bundler/gems/capybara-webkit-e39a5c9ef56e/lib/capybara/webkit/connection.rb:108:in `connect'
  /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/timeout.rb:67:in `timeout'
  /Users/dwt/Library/Ruby/Gems/1.8/bundler/gems/capybara-webkit-e39a5c9ef56e/lib/capybara/webkit/connection.rb:106:in `connect'
  /Users/dwt/Library/Ruby/Gems/1.8/bundler/gems/capybara-webkit-e39a5c9ef56e/lib/capybara/webkit/connection.rb:17:in `initialize'
  /Users/dwt/Library/Ruby/Gems/1.8/bundler/gems/capybara-webkit-e39a5c9ef56e/lib/capybara/webkit/driver.rb:19:in `new'
  /Users/dwt/Library/Ruby/Gems/1.8/bundler/gems/capybara-webkit-e39a5c9ef56e/lib/capybara/webkit/driver.rb:19:in `initialize'
  /Users/dwt/Library/Ruby/Gems/1.8/bundler/gems/capybara-webkit-e39a5c9ef56e/lib/capybara/webkit.rb:11:in `new'
  /Users/dwt/Library/Ruby/Gems/1.8/bundler/gems/capybara-webkit-e39a5c9ef56e/lib/capybara/webkit.rb:11
  /Users/dwt/Library/Ruby/Gems/1.8/gems/capybara-1.1.2/lib/capybara/session.rb:61:in `call'
  /Users/dwt/Library/Ruby/Gems/1.8/gems/capybara-1.1.2/lib/capybara/session.rb:61:in `driver'
  /Users/dwt/Library/Ruby/Gems/1.8/gems/capybara-1.1.2/lib/capybara/session.rb:100:in `body'
  /Users/dwt/Library/Ruby/Gems/1.8/gems/capybara-1.1.2/lib/capybara/dsl.rb:161:in `body'
  /Users/dwt/Code/Projekte/SNTL/yeepa/features/modes/headless/headless.rb:10:in `screen_shot_and_save_page'
  /Users/dwt/Code/Projekte/SNTL/yeepa/features/step_definitions/hooks.rb:3:in `After'
  Invalid argument (Errno::EINVAL)
  /Users/dwt/Library/Ruby/Gems/1.8/bundler/gems/capybara-webkit-e39a5c9ef56e/lib/capybara/webkit/connection.rb:116:in `setsockopt'
  /Users/dwt/Library/Ruby/Gems/1.8/bundler/gems/capybara-webkit-e39a5c9ef56e/lib/capybara/webkit/connection.rb:116:in `attempt_connect'
  /Users/dwt/Library/Ruby/Gems/1.8/bundler/gems/capybara-webkit-e39a5c9ef56e/lib/capybara/webkit/connection.rb:108:in `connect'
  /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/timeout.rb:67:in `timeout'
  /Users/dwt/Library/Ruby/Gems/1.8/bundler/gems/capybara-webkit-e39a5c9ef56e/lib/capybara/webkit/connection.rb:106:in `connect'
  /Users/dwt/Library/Ruby/Gems/1.8/bundler/gems/capybara-webkit-e39a5c9ef56e/lib/capybara/webkit/connection.rb:17:in `initialize'
  /Users/dwt/Library/Ruby/Gems/1.8/bundler/gems/capybara-webkit-e39a5c9ef56e/lib/capybara/webkit/driver.rb:19:in `new'
  /Users/dwt/Library/Ruby/Gems/1.8/bundler/gems/capybara-webkit-e39a5c9ef56e/lib/capybara/webkit/driver.rb:19:in `initialize'
  /Users/dwt/Library/Ruby/Gems/1.8/bundler/gems/capybara-webkit-e39a5c9ef56e/lib/capybara/webkit.rb:11:in `new'
  /Users/dwt/Library/Ruby/Gems/1.8/bundler/gems/capybara-webkit-e39a5c9ef56e/lib/capybara/webkit.rb:11
  /Users/dwt/Library/Ruby/Gems/1.8/gems/capybara-1.1.2/lib/capybara/session.rb:61:in `call'
  /Users/dwt/Library/Ruby/Gems/1.8/gems/capybara-1.1.2/lib/capybara/session.rb:61:in `driver'
  /Users/dwt/Library/Ruby/Gems/1.8/gems/capybara-1.1.2/lib/capybara/session.rb:70:in `reset!'
  /Users/dwt/Library/Ruby/Gems/1.8/gems/capybara-1.1.2/lib/capybara/dsl.rb:87:in `reset_sessions!'
  /Users/dwt/Library/Ruby/Gems/1.8/gems/capybara-1.1.2/lib/capybara/dsl.rb:87:in `each'
  /Users/dwt/Library/Ruby/Gems/1.8/gems/capybara-1.1.2/lib/capybara/dsl.rb:87:in `reset_sessions!'
  /Users/dwt/Library/Ruby/Gems/1.8/gems/capybara-1.1.2/lib/capybara/cucumber.rb:10:in `After'
Please sign in to comment.
Something went wrong with that request. Please try again.