Class: Celluloid::DNS::TCPSocketHandler
Instance Method Summary
collapse
#error_response, #process_query, #stop
Constructor Details
153
154
155
156
157
158
159
|
# File 'lib/celluloid/dns/handler.rb', line 153
def initialize(server, socket)
super(server)
@socket = socket
async.run
end
|
Instance Method Details
#handle_connection(socket) ⇒ Object
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
# File 'lib/celluloid/dns/handler.rb', line 169
def handle_connection(socket)
_, remote_port, remote_host = socket.peeraddr
options = {peer: remote_host, port: remote_port, proto: :tcp}
input_data = StreamTransport.read_chunk(socket)
response = process_query(input_data, options)
length = StreamTransport.write_message(socket, response)
@logger.debug "<#{response.id}> Wrote #{length} bytes via TCP..."
rescue EOFError => error
@logger.warn "<> TCP session ended prematurely!"
rescue Errno::ECONNRESET => error
@logger.warn "<> TCP connection reset by peer!"
rescue DecodeError
@logger.warn "<> Could not decode incoming TCP data!"
ensure
socket.close
end
|
#run ⇒ Object
161
162
163
164
165
166
167
|
# File 'lib/celluloid/dns/handler.rb', line 161
def run
Celluloid.logger.debug(self.class.name) {"-> Run..."}
async.handle_connection(@socket.accept) while @socket
Celluloid.logger.debug(self.class.name) {"<- Run..."}
end
|