Class: Async::DNS::Transport
- Inherits:
-
Object
- Object
- Async::DNS::Transport
- Defined in:
- lib/async/dns/transport.rb
Overview
A simple DNS message stream encoder/decoder.
Instance Method Summary collapse
-
#initialize(socket) ⇒ Transport
constructor
Create a new transport.
-
#read_chunk ⇒ Object
Read a chunk from the socket.
-
#write_chunk(data) ⇒ Object
Write a chunk to the socket.
-
#write_message(message) ⇒ Object
Write a message to the socket.
Constructor Details
#initialize(socket) ⇒ Transport
Create a new transport.
16 17 18 |
# File 'lib/async/dns/transport.rb', line 16 def initialize(socket) @socket = socket end |
Instance Method Details
#read_chunk ⇒ Object
Read a chunk from the socket.
30 31 32 33 34 35 36 37 |
# File 'lib/async/dns/transport.rb', line 30 def read_chunk if size_data = @socket.read(2) # Read in the length, the first two bytes: size = size_data.unpack("n")[0] return @socket.read(size) end end |
#write_chunk(data) ⇒ Object
Write a chunk to the socket.
42 43 44 45 46 47 |
# File 'lib/async/dns/transport.rb', line 42 def write_chunk(data) size_data = [data.bytesize].pack("n") @socket.write(size_data) @socket.write(data) @socket.flush end |
#write_message(message) ⇒ Object
Write a message to the socket.
23 24 25 |
# File 'lib/async/dns/transport.rb', line 23 def () write_chunk(.encode) end |