Module: Net::DNS::MDNS::QueryImp

Includes:
Net::DNS
Included in:
BackgroundQuery, Query
Defined in:
lib/net/dns/mdns.rb

Overview

An mDNS query implementation.

Constant Summary

Constants included from Net::DNS

DecodeError, Net::DNS::Message, Name

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Net::DNS

rrname

Instance Attribute Details

#nameObject (readonly)

The query name from Query.new.



865
866
867
# File 'lib/net/dns/mdns.rb', line 865

def name
  @name
end

#typeObject (readonly)

The query type from Query.new.



867
868
869
# File 'lib/net/dns/mdns.rb', line 867

def type
  @type
end

Instance Method Details

#eachObject

Loop forever, yielding answers as available.



875
876
877
878
879
# File 'lib/net/dns/mdns.rb', line 875

def each # :yield: answers
  loop do
    yield pop
  end
end

#initialize_(name, type = IN::ANY) ⇒ Object



891
892
893
894
895
896
897
898
899
# File 'lib/net/dns/mdns.rb', line 891

def initialize_(name, type = IN::ANY)
  @name = Name.create(name)
  @type = type
  @queue = Queue.new

  qu = @name != "*" ? Question.new(@name, @type) : nil

  Responder.instance.query_start(self, qu)
end

#lengthObject

Number of waiting answers.



882
883
884
# File 'lib/net/dns/mdns.rb', line 882

def length
  @queue.length
end

#popObject

Block, returning answers when available.



870
871
872
# File 'lib/net/dns/mdns.rb', line 870

def pop
  @queue.pop
end

#push(answers) ⇒ Object

:nodoc:



859
860
861
862
# File 'lib/net/dns/mdns.rb', line 859

def push(answers) # :nodoc:
  @queue.push(answers) if answers.first
  self
end

#stopObject



901
902
903
904
# File 'lib/net/dns/mdns.rb', line 901

def stop
  Responder.instance.query_stop(self)
  self
end

#subscribes_to?(an) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


850
851
852
853
854
855
856
857
# File 'lib/net/dns/mdns.rb', line 850

def subscribes_to?(an) # :nodoc:
  if( name.to_s == '*' || name == an.name )
    if( type == IN::ANY || type == an.type )
      return true
    end
  end
  false
end

#to_sObject

A string describing this query.



887
888
889
# File 'lib/net/dns/mdns.rb', line 887

def to_s
  "q?#{name}/#{DNS.rrname(type)}"
end