event_machine: cleanup response_pipe
[rainbows.git] / lib / rainbows / event_machine / response_pipe.rb
blob3b584c734d8a40bd9e417815302c25ac04202e77
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   BUF = ''
8   def initialize(client)
9     @client = client
10   end
12   def notify_readable
13     begin
14       @client.write(@io.read_nonblock(16384, BUF))
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