Class: Async::DNS::StreamHandler
- Inherits:
-
GenericHandler
- Object
- GenericHandler
- Async::DNS::StreamHandler
- Defined in:
- lib/async/dns/handler.rb
Overview
Handle incoming TCP requests, which are stream requests, and pass them on to the given server.
Instance Attribute Summary
Attributes inherited from GenericHandler
#The server that will process incoming queries., #server, #socket
Instance Method Summary collapse
-
#handle_connection(socket) ⇒ Object
Handle an incoming TCP connection.
-
#run(wrapper = ::IO::Endpoint::Wrapper.default, **options) ⇒ Object
Run the handler, processing incoming TCP requests.
Methods inherited from GenericHandler
#The socket to read/write data from/to.=, #error_response, #initialize, #process_query
Constructor Details
This class inherits a constructor from Async::DNS::GenericHandler
Instance Method Details
#handle_connection(socket) ⇒ Object
Handle an incoming TCP connection.
Reads zero or more queries from the given socket and processes them.
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/async/dns/handler.rb', line 135 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.(response) Console.debug "Wrote #{length} bytes via TCP...", response_id: response.id end rescue EOFError => error Console.error(self, "TCP session ended prematurely!", error: error) rescue Errno::ECONNRESET => error Console.error(self, "TCP connection reset by peer!", error: error) rescue Errno::EPIPE => error Console.error(self, "TCP session failed due to broken pipe!", error: error) rescue Resolv::DNS::DecodeError => error Console.error(self, "Could not decode incoming TCP data!", error: error) end |
#run(wrapper = ::IO::Endpoint::Wrapper.default, **options) ⇒ Object
Run the handler, processing incoming TCP requests.
124 125 126 127 128 |
# File 'lib/async/dns/handler.rb', line 124 def run(wrapper = ::IO::Endpoint::Wrapper.default, **) wrapper.accept(@socket, **) do |peer| handle_connection(peer) end end |