EventMachine::Connection
Transmits `Arachni::RPC::Request` objects and calls callbacks once an `Arachni::RPC::Response` is received.
@author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>
Default amount of tries for failed requests.
Prepares an RPC connection and sets {status} to `:idle`.
@param [Hash] opts @option opts [Integer] :max_retries (9)
Default amount of tries for failed requests.
@option opts [Client] :base
Client instance (needed to {Client#push_connection push} ourselves back to its connection pool once we're done and we're ready to be reused.)
# File lib/arachni/rpc/em/client/handler.rb, line 44 def initialize( opts ) @opts = opts.dup @max_retries = @opts[:max_retries] || DEFAULT_TRIES @client = @opts[:client] @opts[:tries] ||= 0 @tries ||= @opts[:tries] @status = :idle @request = nil assume_client_role! end
Closes the connection without triggering a retry operation and sets {status} to `:closed`.
# File lib/arachni/rpc/em/client/handler.rb, line 142 def close_without_retry @request = nil @status = :closed close_connection end
@return [Boolean]
`true` when the connection has been closed, `false` otherwise.
# File lib/arachni/rpc/em/client/handler.rb, line 128 def closed? @status == :closed end
@note If `true`, the connection can be re-used.
@return [Boolean]
`true` when the connection is done, `false` otherwise.
# File lib/arachni/rpc/em/client/handler.rb, line 136 def done? @status == :done end
@note Pushes itself to the client's connection pool to be re-used.
Handles responses to RPC requests, calls its callback and sets {status} to `:done`.
@param [Arachni::RPC::Response] res
# File lib/arachni/rpc/em/client/handler.rb, line 77 def receive_response( res ) if exception?( res ) res.obj = RPC::Exceptions.from_response( res ) end @request.callback.call( res.obj ) if @request.callback ensure @request = nil # Help the GC out. @status = :done @opts[:tries] = @tries = 0 @client.push_connection self end
Handles closed connections, cleans up the SSL session, retries (if necessary) and sets {status} to `:closed`.
@private
# File lib/arachni/rpc/em/client/handler.rb, line 103 def unbind( reason ) end_ssl # If there is a request and a callback and the callback hasn't yet be # called (i.e. not done) then we got here by error so retry. if @request && @request.callback && !done? if retry? #&& reason == Errno::ECONNREFUSED #p 'RETRY' #p @client.connection_count retry_request else #p 'FAIL' #p @client.connection_count e = RPC::Exceptions::ConnectionError.new( "Connection closed [#{reason}]" ) @request.callback.call( e ) @client.connection_failed self end return end close_without_retry end
Generated with the Darkfish Rdoc Generator 2.