Class: Async::DNS::StreamHandler

Inherits:
GenericHandler show all
Defined in:
lib/async/dns/handler.rb

Instance Attribute Summary

Attributes inherited from GenericHandler

#server, #socket

Instance Method Summary collapse

Methods inherited from GenericHandler

#error_response, #initialize, #process_query

Constructor Details

This class inherits a constructor from Async::DNS::GenericHandler

Instance Method Details

#handle_connection(socket) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/async/dns/handler.rb', line 117

def handle_connection(socket)
	transport = Transport.new(socket)
	
	while input_data = transport.read_chunk
		response = process_query(input_data, remote_address: socket.remote_address)
		length = transport.write_message(response)
		
		@logger.debug "<#{response.id}> Wrote #{length} bytes via TCP..."
	end
rescue EOFError => error
	@logger.warn "<> Error: TCP session ended prematurely!"
rescue Errno::ECONNRESET => error
	@logger.warn "<> Error: TCP connection reset by peer!"
rescue Errno::EPIPE
	@logger.warn "<> Error: TCP session failed due to broken pipe!"
rescue DecodeError
	@logger.warn "<> Error: Could not decode incoming TCP data!"
end

#run(backlog = Socket::SOMAXCONN) ⇒ Object



109
110
111
112
113
114
115
# File 'lib/async/dns/handler.rb', line 109

def run(backlog = Socket::SOMAXCONN)
	@socket.listen(backlog)
	
	@socket.accept_each do |client, address|
		handle_connection(client)
	end
end