class Async::DNS::Transport
Public Class Methods
new(socket)
click to toggle source
# File lib/async/dns/transport.rb, line 33 def initialize(socket) @stream = IO::Stream.new(socket) end
Public Instance Methods
read_chunk()
click to toggle source
# File lib/async/dns/transport.rb, line 41 def read_chunk if size_data = @stream.read(2) # Read in the length, the first two bytes: size = size_data.unpack('n')[0] return @stream.read(size) end end
write_chunk(output_data)
click to toggle source
# File lib/async/dns/transport.rb, line 50 def write_chunk(output_data) size_data = [output_data.bytesize].pack('n') @stream.write(size_data) @stream.write(output_data) @stream.flush return output_data.bytesize end
write_message(message)
click to toggle source
# File lib/async/dns/transport.rb, line 37 def write_message(message) write_chunk(message.encode) end