Receive the data via a TCP connection, process messages when we receive the indicated amount of data.
# File lib/rubydns/handler.rb, line 105 def receive_data(data) # We buffer data until we've received the entire packet: @buffer.write(data) # Message includes a 16-bit length field.. we need to see if we have received it yet: if @length == nil if (@buffer.size - @processed) < 2 raise LengthError.new("Malformed message smaller than two bytes received") end # Grab the length field: @length = @buffer.string.byteslice(@processed, 2).unpack('n')[0] @processed += 2 end if (@buffer.size - @processed) >= @length data = @buffer.string.byteslice(@processed, @length) options = {:peer => RubyDNS::get_peer_details(self)} UDPHandler.process(@server, data, options) do |answer| data = answer.encode @server.logger.debug "Writing response to client (#{data.bytesize} bytes) via TCP..." self.send_data([data.bytesize].pack('n')) self.send_data(data) end @processed += @length @length = nil end end
Generated with the Darkfish Rdoc Generator 2.