Module: RubyDNS::Resolver::Request::TCPRequestHandler
- Defined in:
- lib/rubydns/resolver.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.open(host, port, request) ⇒ Object
226 227 228 |
# File 'lib/rubydns/resolver.rb', line 226 def self.open(host, port, request) EventMachine::connect(host, port, TCPRequestHandler, request) end |
Instance Method Details
#initialize(request) ⇒ Object
230 231 232 233 234 |
# File 'lib/rubydns/resolver.rb', line 230 def initialize(request) @request = request @buffer = nil @length = nil end |
#post_init ⇒ Object
236 237 238 239 240 241 |
# File 'lib/rubydns/resolver.rb', line 236 def post_init data = @request.packet send_data([data.bytesize].pack('n')) send_data data end |
#receive_data(data) ⇒ Object
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/rubydns/resolver.rb', line 243 def receive_data(data) # We buffer data until we've received the entire packet: @buffer ||= BinaryStringIO.new @buffer.write(data) # If we've received enough data and we haven't figured out the length yet... if @length == nil and @buffer.size > 2 # Extract the length from the buffer: @length = @buffer.string.byteslice(0, 2).unpack('n')[0] end # If we know what the length is, and we've got that much data, we can decode the message: if @length != nil and @buffer.size >= (@length + 2) data = @buffer.string.byteslice(2, @length) = RubyDNS::(data) @request.process_response!() end # If we have received more data than expected, should this be an error? rescue Resolv::DNS::DecodeError => error @request.process_response!(error) end |