rainbows.git  about / heads / tags
Unicorn for sleepy apps and slow clients
blob 1f7b08a2a0c4214d30eab0d5b7069bc2c0dc00e3 568 bytes (raw)
$ git show v3.2.0:lib/rainbows/event_machine/response_pipe.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 
# -*- encoding: binary -*-
# :enddoc:
module Rainbows::EventMachine::ResponsePipe
  # garbage avoidance, EM always uses this in a single thread,
  # so a single buffer for all clients will work safely
  RBUF = Rainbows::EvCore::RBUF

  def initialize(client)
    @client = client
  end

  def notify_readable
    case data = Kgio.tryread(@io, 16384, RBUF)
    when String
      @client.write(data)
    when :wait_readable
      return
    when nil
      return detach
    end while true
  end

  def unbind
    @client.next!
    @io.close unless @io.closed?
  end
end

git clone https://yhbt.net/rainbows.git