about summary refs log tree commit homepage
path: root/lib/rainbows
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-07-19 10:09:54 +0000
committerEric Wong <normalperson@yhbt.net>2010-07-19 17:04:24 -0700
commitb3278b45bd5e31d97ce7b8625585692091ff4755 (patch)
tree4564e51bc7ffbda655df0415bb70527df44c891f /lib/rainbows
parent549b25fd501b0df4a4a8b5edccde6101edb0cd63 (diff)
downloadrainbows-b3278b45bd5e31d97ce7b8625585692091ff4755.tar.gz
Since the EM loop runs entirely in one thread, we can get away
with using a single buffer across all pipe/socket responses.
Diffstat (limited to 'lib/rainbows')
-rw-r--r--lib/rainbows/event_machine.rb8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/rainbows/event_machine.rb b/lib/rainbows/event_machine.rb
index 4d5156e..3837e1f 100644
--- a/lib/rainbows/event_machine.rb
+++ b/lib/rainbows/event_machine.rb
@@ -158,13 +158,17 @@ module Rainbows
     end
 
     module ResponsePipe # :nodoc: all
+      # garbage avoidance, EM always uses this in a single thread,
+      # so a single buffer for all clients will work safely
+      BUF = ''
+
       def initialize(client)
         @client = client
       end
 
       def notify_readable
         begin
-          @client.write(@io.read_nonblock(16384))
+          @client.write(@io.read_nonblock(16384, BUF))
         rescue Errno::EINTR
           retry
         rescue Errno::EAGAIN
@@ -192,7 +196,7 @@ module Rainbows
       def notify_readable
         begin
           data = begin
-            @io.read_nonblock(16384)
+            @io.read_nonblock(16384, BUF)
           rescue Errno::EINTR
             retry
           rescue Errno::EAGAIN