Class: EventMachine::DNS::Request
- Inherits:
-
Object
- Object
- EventMachine::DNS::Request
- Includes:
- EventMachine::Deferrable
- Defined in:
- lib/em/resolver.rb
Constant Summary
Constants included from EventMachine::Deferrable
EventMachine::Deferrable::Pool
Instance Attribute Summary collapse
-
#max_tries ⇒ Object
Returns the value of attribute max_tries.
-
#retry_interval ⇒ Object
Returns the value of attribute retry_interval.
Instance Method Summary collapse
-
#initialize(socket, hostname) ⇒ Request
constructor
A new instance of Request.
- #receive_answer(msg) ⇒ Object
- #tick ⇒ Object
Methods included from EventMachine::Deferrable
#callback, #cancel_callback, #cancel_errback, #cancel_timeout, #errback, #fail, future, #set_deferred_status, #succeed, #timeout
Constructor Details
#initialize(socket, hostname) ⇒ Request
Returns a new instance of Request.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/em/resolver.rb', line 138 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 end |
Instance Attribute Details
#max_tries ⇒ Object
Returns the value of attribute max_tries.
136 137 138 |
# File 'lib/em/resolver.rb', line 136 def max_tries @max_tries end |
#retry_interval ⇒ Object
Returns the value of attribute retry_interval.
136 137 138 |
# File 'lib/em/resolver.rb', line 136 def retry_interval @retry_interval end |
Instance Method Details
#receive_answer(msg) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/em/resolver.rb', line 164 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 end |
#tick ⇒ Object
153 154 155 156 157 158 159 160 161 162 |
# File 'lib/em/resolver.rb', line 153 def tick # Break early if nothing to do return if @last_send + @retry_interval > Time.now if @tries < @max_tries send else @socket.deregister_request(@id, self) fail 'retries exceeded' end end |