diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-07-19 10:09:53 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2010-07-19 17:04:23 -0700 |
commit | 549b25fd501b0df4a4a8b5edccde6101edb0cd63 (patch) | |
tree | d0ba43edb1b6ca84a4f89207dcc7397e57c3a9c8 /lib/rainbows/event_machine.rb | |
parent | 12205e29b29f844295d1794bfe10634646541f20 (diff) | |
download | rainbows-549b25fd501b0df4a4a8b5edccde6101edb0cd63.tar.gz |
Using EM.enable_proxy with EM.attach seems to cause EM::Connection#receive_data callbacks to be fired before the proxy has a chance to act, leading the first few chunks of data being lost in the default receive_data handler. Instead just rely on EM.watch like the chunked pipe.
Diffstat (limited to 'lib/rainbows/event_machine.rb')
-rw-r--r-- | lib/rainbows/event_machine.rb | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/rainbows/event_machine.rb b/lib/rainbows/event_machine.rb index 77fc962..4d5156e 100644 --- a/lib/rainbows/event_machine.rb +++ b/lib/rainbows/event_machine.rb @@ -106,11 +106,8 @@ module Rainbows else do_chunk = false end - if do_chunk - EM.watch(io, ResponseChunkPipe, self).notify_readable = true - else - EM.enable_proxy(EM.attach(io, ResponsePipe, self), self, 16384) - end + mod = do_chunk ? ResponseChunkPipe : ResponsePipe + EM.watch(io, mod, self).notify_readable = true end def em_write_response(response, alive = false) @@ -165,6 +162,19 @@ module Rainbows @client = client end + def notify_readable + begin + @client.write(@io.read_nonblock(16384)) + rescue Errno::EINTR + retry + rescue Errno::EAGAIN + return + rescue EOFError + detach + return + end while true + end + def unbind @io.close @client.quit |