class XRBP::WebSocket::Plugins::ConnectionTimeout
Automatic disconnection if no server data in certain time
@example timed out connection
connection = WebSocket::Connection.new "wss://s1.ripple.com:443" connection.add_plugin :connection_timeout connection.connection_timeout = 3 connection.connect sleep(3) connection.closed? # => true
Constants
- DEFAULT_TIMEOUT
Attributes
connection_timeout[RW]
Public Class Methods
new(connection)
click to toggle source
Calls superclass method
XRBP::PluginBase::new
# File lib/xrbp/websocket/plugins/connection_timeout.rb, line 20 def initialize(connection) super(connection) @connection_timeout = DEFAULT_TIMEOUT end
Public Instance Methods
added()
click to toggle source
# File lib/xrbp/websocket/plugins/connection_timeout.rb, line 29 def added plugin = self connection.define_instance_method(:connection_timeout=) do |t| plugin.connection_timeout = t connections.each{ |c| c.plugin(ConnectionTimeout) .connection_timeout = t } if self.kind_of?(MultiConnection) end end
closed()
click to toggle source
# File lib/xrbp/websocket/plugins/connection_timeout.rb, line 57 def closed terminate! end
message(msg)
click to toggle source
# File lib/xrbp/websocket/plugins/connection_timeout.rb, line 41 def message(msg) @last_msg = Time.now end
opened()
click to toggle source
# File lib/xrbp/websocket/plugins/connection_timeout.rb, line 45 def opened connection.add_work do @last_msg = Time.now until terminate? || connection.force_quit? || connection.closed? connection.async_close! if timeout? connection.rsleep(0.1) end end end
timeout?()
click to toggle source
# File lib/xrbp/websocket/plugins/connection_timeout.rb, line 25 def timeout? Time.now - @last_msg > @connection_timeout end