Class: Caldecott::Server::HttpTunnel
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- Caldecott::Server::HttpTunnel
- Defined in:
- lib/caldecott/server/http_tunnel.rb
Constant Summary collapse
- @@tunnels =
{}
Class Method Summary collapse
-
.start_timer(inactive_timeout = 3600, sweep_interval = 300) ⇒ Object
defaults are 1 hour of inactivity with sweeps every 5 minutes.
- .tunnels ⇒ Object
Instance Method Summary collapse
Class Method Details
.start_timer(inactive_timeout = 3600, sweep_interval = 300) ⇒ Object
defaults are 1 hour of inactivity with sweeps every 5 minutes
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/caldecott/server/http_tunnel.rb', line 135 def self.start_timer(inactive_timeout = 3600, sweep_interval = 300) EventMachine::add_periodic_timer sweep_interval do # This is needed because there seems to have a bug on the # Connection#set_comm_inactivity_timeout (int overflow ) # Look at eventmachine/ext/em.cpp 2289 # It reaps the inactive connections # # We also can not seem to add our own timer per tunnel instance. # When we do, the ruby interpreter freaks out and starts throwing # # errors like: # undefined method `cancel' for 57:Fixnum # # for code like the following during shutdown: # @inactivity_timer.cancel if @inactivity_timer # @inactivity_timer.cancel # @inactivity_timer = nil @@tunnels.each do |id, t| t.delete if (Time.now - t.last_active_at) > inactive_timeout end end end |
.tunnels ⇒ Object
130 131 132 |
# File 'lib/caldecott/server/http_tunnel.rb', line 130 def self.tunnels @@tunnels end |
Instance Method Details
#tunnel_from_id(tun_id) ⇒ Object
158 159 160 161 162 163 |
# File 'lib/caldecott/server/http_tunnel.rb', line 158 def tunnel_from_id(tun_id) tun = @@tunnels[tun_id] not_found("tunnel #{tun_id} does not exist\n") unless tun tun.log.debug "#{request.request_method} #{request.url}" tun end |