def run(background=true)
BasicSocket.do_not_reverse_lookup = true
@status = :run
@thread_pool = ThreadPool.new(@min_threads,
@max_threads,
IOBuffer) do |client, buffer|
process_now = false
begin
process_now = client.eagerly_finish
rescue HttpParserError => e
client.write_400
client.close
@events.parse_error self, client.env, e
rescue ConnectionError
client.close
else
if process_now
process_client client, buffer
else
client.set_timeout @first_data_timeout
@reactor.add client
end
end
end
@reactor = Reactor.new self, @thread_pool
@reactor.run_in_thread
if @auto_trim_time
@thread_pool.auto_trim!(@auto_trim_time)
end
if background
@thread = Thread.new { handle_servers }
return @thread
else
handle_servers
end
end