diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-12-16 23:57:08 -0800 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-12-16 23:57:08 -0800 |
commit | 5dea67ecf3dd868e7b375312cdef2c4651b11437 (patch) | |
tree | 106856f38f3e4b8934af0a584345ea09644b4b5e | |
parent | 52ad3f270e758e5bfdfe965cbecbd20d5048062f (diff) | |
download | rainbows-5dea67ecf3dd868e7b375312cdef2c4651b11437.tar.gz |
-rw-r--r-- | lib/rainbows/base.rb | 7 | ||||
-rw-r--r-- | lib/rainbows/error.rb | 9 | ||||
-rw-r--r-- | lib/rainbows/fiber/base.rb | 2 | ||||
-rw-r--r-- | lib/rainbows/revactor.rb | 13 |
4 files changed, 12 insertions, 19 deletions
diff --git a/lib/rainbows/base.rb b/lib/rainbows/base.rb index a735b82..9bbe049 100644 --- a/lib/rainbows/base.rb +++ b/lib/rainbows/base.rb @@ -10,11 +10,6 @@ module Rainbows include Rainbows::Const G = Rainbows::G - def handle_error(client, e) - msg = Error.response(e) and client.write_nonblock(msg) - rescue - end - def init_worker_process(worker) super(worker) G.tmp = worker.tmp @@ -65,7 +60,7 @@ module Rainbows # if the socket is already closed or broken. We'll always ensure # the socket is closed at the end of this function rescue => e - handle_error(client, e) + Error.write(client, e) ensure client.close end diff --git a/lib/rainbows/error.rb b/lib/rainbows/error.rb index 2d8cd94..1e25626 100644 --- a/lib/rainbows/error.rb +++ b/lib/rainbows/error.rb @@ -4,6 +4,15 @@ module Rainbows class Error class << self + # if we get any error, try to write something back to the client + # assuming we haven't closed the socket, but don't get hung up + # if the socket is already closed or broken. We'll always ensure + # the socket is closed at the end of this function + def write(io, e) + msg = Error.response(e) and io.write_nonblock(msg) + rescue + end + def app(e) G.server.logger.error "app error: #{e.inspect}" G.server.logger.error e.backtrace.join("\n") diff --git a/lib/rainbows/fiber/base.rb b/lib/rainbows/fiber/base.rb index 995b4af..1617c54 100644 --- a/lib/rainbows/fiber/base.rb +++ b/lib/rainbows/fiber/base.rb @@ -99,7 +99,7 @@ module Rainbows HttpResponse.write(client, response, out) end while alive and hp.reset.nil? and env.clear rescue => e - handle_error(io, e) + Error.write(io, e) ensure G.cur -= 1 RD.delete(client) diff --git a/lib/rainbows/revactor.rb b/lib/rainbows/revactor.rb index ff0e429..b410bda 100644 --- a/lib/rainbows/revactor.rb +++ b/lib/rainbows/revactor.rb @@ -68,7 +68,7 @@ module Rainbows end while alive and hp.reset.nil? and env.clear rescue ::Revactor::TCP::ReadError rescue => e - handle_error(client, e) + Error.write(client.instance_eval { @_io }, e) ensure client.close end @@ -121,17 +121,6 @@ module Rainbows rescue Errno::EMFILE => e end - # if we get any error, try to write something back to the client - # assuming we haven't closed the socket, but don't get hung up - # if the socket is already closed or broken. We'll always ensure - # the socket is closed at the end of this function - def handle_error(client, e) - # this is Revactor implementation dependent - msg = Error.response(e) and - client.instance_eval { @_io.write_nonblock(msg) } - rescue - end - def revactorize_listeners LISTENERS.map do |s| case s |