class StreamHandler
Handle incoming TCP requests, which are stream requests, and pass them on to the given server.
Definitions
def run(wrapper = ::IO::Endpoint::Wrapper.default, **options)
Run the handler, processing incoming TCP requests.
Signature
-
parameter
wrapper
Interface(:async)
The parent task to run the handler under.
Implementation
def run(wrapper = ::IO::Endpoint::Wrapper.default, **options)
wrapper.accept(@socket, **options) do |peer|
handle_connection(peer)
end
end
def handle_connection(socket)
Handle an incoming TCP connection.
Reads zero or more queries from the given socket and processes them.
Signature
-
parameter
socket
Socket
The incoming TCP connection.
Implementation
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)
Console.debug "Wrote #{length} bytes via TCP...", response_id: response.id
end
rescue EOFError => error
Console::Event::Failure.for(error).emit "TCP session ended prematurely!"
rescue Errno::ECONNRESET => error
Console::Event::Failure.for(error).emit "TCP connection reset by peer!"
rescue Errno::EPIPE => error
Console::Event::Failure.for(error).emit "TCP session failed due to broken pipe!"
rescue Resolv::DNS::DecodeError => error
Console::Event::Failure.for(error).emit "Could not decode incoming TCP data!"
end