Class: Dnsruby::EventMachineInterface::EmTcpHandler

Inherits:
EmUdpHandler
  • Object
show all
Defined in:
lib/Dnsruby/event_machine_interface.rb

Overview

:nodoc: all

Instance Attribute Summary

Attributes inherited from EmUdpHandler

#closing, #timeout_time

Instance Method Summary collapse

Methods inherited from EmUdpHandler

#process_incoming_message, #send_timeout, #send_to_client, #unbind

Instance Method Details

#post_initObject



240
241
242
243
244
# File 'lib/Dnsruby/event_machine_interface.rb', line 240

def post_init
  super
  @data=""
  @answersize = 0
end

#receive_data(data) ⇒ Object



245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/Dnsruby/event_machine_interface.rb', line 245

def receive_data(data)
  TheLog.debug("TCP receive_data called")
  #Buffer up the incoming data until we have a complete packet
  @data << data
  if (@data.length >= 2)
    if (@answersize == 0)
      @answersize = @data[0..1].unpack('n')[0]
      TheLog.debug("TCP - expecting #{@answersize} bytes")
    end
    if (@answersize == @data.length - 2)
      TheLog.debug("TCP - got all #{@answersize} bytes ")
      process_incoming_message(@data[2..@data.length])
    else
      TheLog.debug("TCP - got #{@data.length-2} message bytes")
    end
  end
end