EventMachine::Connection
# File lib/brb/tunnel.rb, line 22 def initialize(opts = {}) super @object = opts[:object] @verbose = opts[:verbose] BrB.logger.level = @verbose ? Logger::INFO : Logger::WARN @timeout_rcv_value = opts[:timeout] || 30 # Currently not implemented due to the lack of performance of ruby Timeout @close_after_timeout = opts[:close_after_timeout] || false @uri = opts[:uri] @replock = Mutex.new @responses = {} @block = opts[:block] @queue = Queue.new @buffer = '' # Callbacks handling : @callbacks = {} @callbacks_mutex = Mutex.new end
Return true if the tunnel is currently active
# File lib/brb/tunnel.rb, line 80 def active? @active end
# File lib/brb/tunnel.rb, line 53 def close_connection(after_writing = false) @active = false super end
When no method is found on tunnel interface, create an brb out request
# File lib/brb/tunnel.rb, line 85 def method_missing(meth, *args, &block) return nil if !@active new_brb_out_request(meth, *args, &block) end
EventMachine Callback, called after connection has been initialized
# File lib/brb/tunnel.rb, line 43 def post_init BrB.logger.info " [BrB] Tunnel initialized on #{@uri}" @active = true if @block EM.defer do @block.call(:register, self) end end end
Stop the service
# File lib/brb/tunnel.rb, line 71 def stop_service BrB.logger.info ' [BrB] Stopping Tunnel service...' @active = false EM.schedule do close_connection end end
EventMachine unbind event The connection has been closed
# File lib/brb/tunnel.rb, line 60 def unbind BrB.logger.info ' [BrB] Tunnel service closed' @active = false if @block EM.defer do @block.call(:unregister, self) end end end
Generated with the Darkfish Rdoc Generator 2.