Skip to content

Instantly share code, notes, and snippets.

@phiggins
Created December 6, 2010 17:22
Show Gist options
  • Save phiggins/730598 to your computer and use it in GitHub Desktop.
Save phiggins/730598 to your computer and use it in GitHub Desktop.
comm_inactivity_timeout
require 'eventmachine'
# Code adapted from here:
# https://github.com/eventmachine/eventmachine/blob/master/tests/test_inactivity_timeout.rb#L36
start, finish = nil
timeout_handler = Module.new do
define_method :unbind do
finish = Time.now
EM.stop
end
end
EM.run {
EM.heartbeat_interval = 0.1
EM.start_server("127.0.0.1", 12345)
EM.add_timer(0.1) {
start = Time.now
c = EM.connect("127.0.0.1", 12345, timeout_handler)
c.comm_inactivity_timeout = 0.2
}
}
puts finish - start
# linux
# $ ruby -Ilib test_inactivity_timeout.rb
# 0.200822293
#
# winxp
# >ruby -Ilib test_inactivity_timeout.rb
# 200.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment