Class: Net::DNS::MDNS::BackgroundQuery

Inherits:
Object
  • Object
show all
Includes:
QueryImp
Defined in:
lib/net/dns/mdns.rb

Overview

An mDNS query.

Constant Summary

Constants included from Net::DNS

DecodeError, Net::DNS::Message, Name

Instance Attribute Summary

Attributes included from QueryImp

#name, #type

Instance Method Summary collapse

Methods included from QueryImp

#each, #initialize_, #length, #pop, #push, #subscribes_to?, #to_s

Methods included from Net::DNS

rrname

Constructor Details

#initialize(name, type = IN::ANY, &proc) ⇒ BackgroundQuery

This is like Query.new, except the block is yielded in a background thread, and is not optional.

In the thread, self and any answers are yielded until an explicit break, return, or #stop is done.



941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
# File 'lib/net/dns/mdns.rb', line 941

def initialize(name, type = IN::ANY, &proc) #:yield: self, answers
  unless proc
    raise ArgumentError, "require a proc to yield in background!"
  end

  initialize_(name, type)

  @thread = Thread.new do
    begin
      loop do
        answers = self.pop

        proc.call(self, answers)
      end
    rescue
      # This is noisy, but better than silent failure. If you don't want
      # me to print your exceptions, make sure they don't get out of your
      # block!
      $stderr.puts "query #{self} yield raised #{$!}"
      $!.backtrace.each do |e| $stderr.puts(e) end
    ensure
      Responder.instance.query_stop(self)
    end
  end
end

Instance Method Details

#stopObject



967
968
969
970
# File 'lib/net/dns/mdns.rb', line 967

def stop
  @thread.kill
  self
end