about summary refs log tree commit homepage
path: root/lib/rainbows/event_machine.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rainbows/event_machine.rb')
-rw-r--r--lib/rainbows/event_machine.rb20
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