lib/midori/server.rb in em-midori-0.2.3 vs lib/midori/server.rb in em-midori-0.2.4
- old
+ new
@@ -26,11 +26,10 @@
# @param [String] monitor the socket able to read
def receive_data(monitor)
lambda do
async_fiber(Fiber.new do
begin
- start_time = Time.now
_sock_domain, remote_port, _remote_hostname, remote_ip = monitor.io.peeraddr
port, ip = remote_port, remote_ip
@request.ip = ip
@request.port = port
data = monitor.io.read_nonblock(16_384)
@@ -38,12 +37,10 @@
websocket_request(StringIO.new(data))
else
@request.parse(data)
receive_new_request if @request.parsed && @request.body_parsed?
end
- now_time = Time.now
- @logger.info "#{@request.ip} - - \"#{@request.method} #{@request.path} HTTP/#{@request.protocol.join('.')}\" #{@response.status} #{(now_time.to_f - start_time.to_f).round(6)}".green
rescue => e
close_connection
@logger.warn "#{@request.ip} - - #{e.backtrace.join("\n")}".yellow
end
end)
@@ -51,10 +48,13 @@
end
# Logic of receiving new request
def receive_new_request
begin
+ start_time = Time.now
@response = @api.receive(request, self)
+ now_time = Time.now
+ @logger.info "#{@request.ip} - - \"#{@request.method} #{@request.path} HTTP/#{@request.protocol.join('.')}\" #{@response.status} #{sprintf("%.6f", now_time.to_f - start_time.to_f)}".green
call_event(:open) if @request.websocket?
rescue Midori::Exception::NotFound => e
@response = Midori::Sandbox.capture(e)
rescue => e
@response = Midori::Sandbox.capture(e)