rainbows.git  about / heads / tags
Unicorn for sleepy apps and slow clients
blob 2417dbe56e00156a96aca205e7e4221a9b24e6fc 696 bytes (raw)
$ git show v0.97.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
28
29
30
 
# -*- 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
  BUF = ''

  def initialize(client, alive, body)
    @client, @alive, @body = client, alive, body
  end

  def notify_readable
    begin
      @client.write(@io.read_nonblock(16384, BUF))
    rescue Errno::EINTR
    rescue Errno::EAGAIN
      return
    rescue EOFError
      detach
      return
    end while true
  end

  def unbind
    @client.body = nil
    @alive ? @client.on_read('') : @client.quit
    @body.close if @body.respond_to?(:close)
    @io.close unless @io.closed?
  end
end

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