bump required Unicorn dependency for Kgio
[rainbows.git] / lib / rainbows / event_machine / response_pipe.rb
blob1f7b08a2a0c4214d30eab0d5b7069bc2c0dc00e3
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     case data = Kgio.tryread(@io, 16384, RBUF)
14     when String
15       @client.write(data)
16     when :wait_readable
17       return
18     when nil
19       return detach
20     end while true
21   end
23   def unbind
24     @client.next!
25     @io.close unless @io.closed?
26   end
27 end