Skip to content

Commit

Permalink
Fix indentation warnings in EM::DNS::Resolver.
Browse files Browse the repository at this point in the history
  • Loading branch information
phiggins committed May 24, 2011
1 parent 7497dd1 commit 3f7ae87
Showing 1 changed file with 64 additions and 64 deletions.
128 changes: 64 additions & 64 deletions lib/em/resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,88 +105,88 @@ def receive_data(data)
begin
msg = Resolv::DNS::Message.decode data
rescue
else
req = @requests[msg.id]
if req
@requests.delete(msg.id)
req.receive_answer(msg)
end
else
req = @requests[msg.id]
if req
@requests.delete(msg.id)
req.receive_answer(msg)
end
end
end
end

class Request
include Deferrable
attr_accessor :retry_interval, :max_tries
class Request
include Deferrable
attr_accessor :retry_interval, :max_tries

def initialize(socket, hostname)
@socket = socket
@hostname = hostname
@tries = 0
@last_send = Time.at(0)
@retry_interval = 3
@max_tries = 5
def initialize(socket, hostname)
@socket = socket
@hostname = hostname
@tries = 0
@last_send = Time.at(0)
@retry_interval = 3
@max_tries = 5

if addrs = Resolver.hosts[hostname]
succeed addrs
else
EM.next_tick { tick }
end
if addrs = Resolver.hosts[hostname]
succeed addrs
else
EM.next_tick { tick }
end
end

def tick
# Break early if nothing to do
return if @last_send + @retry_interval > Time.now
if @tries < @max_tries
send
else
fail 'retries exceeded'
end
def tick
# Break early if nothing to do
return if @last_send + @retry_interval > Time.now
if @tries < @max_tries
send
else
fail 'retries exceeded'
end
end

def receive_answer(msg)
addrs = []
msg.each_answer do |name,ttl,data|
if data.kind_of?(Resolv::DNS::Resource::IN::A) ||
data.kind_of?(Resolv::DNS::Resource::IN::AAAA)
addrs << data.address.to_s
end
def receive_answer(msg)
addrs = []
msg.each_answer do |name,ttl,data|
if data.kind_of?(Resolv::DNS::Resource::IN::A) ||
data.kind_of?(Resolv::DNS::Resource::IN::AAAA)
addrs << data.address.to_s
end
end

if addrs.empty?
fail "rcode=#{msg.rcode}"
else
succeed addrs
end
if addrs.empty?
fail "rcode=#{msg.rcode}"
else
succeed addrs
end
end

private
private

def send
@tries += 1
@last_send = Time.now
@socket.send_packet(packet.encode)
end
def send
@tries += 1
@last_send = Time.now
@socket.send_packet(packet.encode)
end

def id
begin
@id = rand(65535)
@socket.register_request(@id, self)
rescue RequestIdAlreadyUsed
retry
end unless defined?(@id)
def id
begin
@id = rand(65535)
@socket.register_request(@id, self)
rescue RequestIdAlreadyUsed
retry
end unless defined?(@id)

@id
end
@id
end

def packet
msg = Resolv::DNS::Message.new
msg.id = id
msg.rd = 1
msg.add_question @hostname, Resolv::DNS::Resource::IN::A
msg
end
def packet
msg = Resolv::DNS::Message.new
msg.id = id
msg.rd = 1
msg.add_question @hostname, Resolv::DNS::Resource::IN::A
msg
end

end
end
end
end

0 comments on commit 3f7ae87

Please sign in to comment.