# File lib/em-http/http_connection.rb, line 52 def activate_connection(client) begin EventMachine.bind_connect(@connopts.bind, @connopts.bind_port, @connopts.host, @connopts.port, HttpStubConnection) do |conn| post_init @deferred = false @conn = conn conn.parent = self conn.pending_connect_timeout = @connopts.connect_timeout conn.comm_inactivity_timeout = @connopts.inactivity_timeout end finalize_request(client) rescue EventMachine::ConnectionError => e # # Currently, this can only fire on initial connection setup # since #connect is a synchronous method. Hence, rescue the exception, # and return a failed deferred which fail any client request at next # tick. We fail at next tick to keep a consistent API when the newly # created HttpClient is failed. This approach has the advantage to # remove a state check of @deferred_status after creating a new # HttpRequest. The drawback is that users may setup a callback which we # know won't be used. # # Once there is async-DNS, then we'll iterate over the outstanding # client requests and fail them in order. # # Net outcome: failed connection will invoke the same ConnectionError # message on the connection deferred, and on the client deferred. # EM.next_tick{client.close(e.message)} end end