ev_core: reuse buffer to avoid GC thrashing
[rainbows.git] / lib / rainbows / event_machine / response_pipe.rb
blob0ea1eae3a10e20b2497b6125a9fbe2ae080c72ee
1 # -*- encoding: binary -*-
2 # :enddoc:
3 module Rainbows::EventMachine::ResponsePipe
4   # garbage avoidance, EM always uses this in a single thread,
5   # so a single buffer for all clients will work safely
6   RBUF = Rainbows::EvCore::RBUF
8   def initialize(client)
9     @client = client
10   end
12   def notify_readable
13     begin
14       @client.write(@io.read_nonblock(16384, RBUF))
15     rescue Errno::EINTR
16     rescue Errno::EAGAIN
17       return
18     rescue EOFError
19       detach
20       return
21     end while true
22   end
24   def unbind
25     @client.next!
26     @io.close unless @io.closed?
27   end
28 end