several response body#close fixes
[rainbows.git] / lib / rainbows / event_machine / response_pipe.rb
blob3da2417ece51ba8cb19e53e9b4cf641d5aae5e97
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, alive, body)
9     @client, @alive, @body = client, alive, body
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     @body.close if @body.respond_to?(:close)
26     @client.next!
27     @io.close unless @io.closed?
28   end
29 end