Sha256: 24520e259ab09b675a57145b651cba27f5c123c168c617c0e37e4ceedfb5fe16

Contents?: true

Size: 1.44 KB

Versions: 13

Compression:

Stored size: 1.44 KB

Contents

# -*- encoding: binary -*-
# :enddoc:
module Rainbows::Revactor::Client::Methods
  if IO.method_defined?(:trysendfile)
    def write_body_file(body, range)
      body, client = body_to_io(body), @client
      sock = @client.instance_variable_get(:@_io)
      pfx = Revactor::TCP::Socket === client ? :tcp : :unix
      write_complete = T[:"#{pfx}_write_complete", client]
      closed = T[:"#{pfx}_closed", client]
      offset, count = range ? range : [ 0, body.stat.size ]
      case n = sock.trysendfile(body, offset, count)
      when Integer
        offset += n
        return if 0 == (count -= n)
      when :wait_writable
        # The @_write_buffer is empty at this point, trigger the
        # on_readable method which in turn triggers on_write_complete
        # even though nothing was written
        client.controller = Actor.current
        client.__send__(:enable_write_watcher)
        Actor.receive do |filter|
          filter.when(write_complete) {}
          filter.when(closed) { raise Errno::EPIPE }
        end
      else # nil
        return
      end while true
      ensure
        close_if_private(body)
    end
  end

  def handle_error(e)
    Revactor::TCP::ReadError === e or super
  end

  def write_response(status, headers, body, alive)
    super(status, headers, body, alive)
    alive && @ts and @hp.buf << @ts.leftover
  end

  def self.included(klass)
    klass.__send__ :alias_method, :write_body_stream, :write_body_each
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
rainbows-4.4.3 lib/rainbows/revactor/client/methods.rb
rainbows-4.4.2 lib/rainbows/revactor/client/methods.rb
rainbows-4.4.1.1.gd5c8c lib/rainbows/revactor/client/methods.rb
rainbows-4.4.1 lib/rainbows/revactor/client/methods.rb
rainbows-4.4.0 lib/rainbows/revactor/client/methods.rb
rainbows-4.3.1 lib/rainbows/revactor/client/methods.rb
rainbows-4.3.0 lib/rainbows/revactor/client/methods.rb
rainbows-4.2.0 lib/rainbows/revactor/client/methods.rb
rainbows-4.1.0 lib/rainbows/revactor/client/methods.rb
rainbows-4.0.0 lib/rainbows/revactor/client/methods.rb
rainbows-3.4.0 lib/rainbows/revactor/client/methods.rb
rainbows-3.3.0 lib/rainbows/revactor/client/methods.rb
rainbows-3.2.0 lib/rainbows/revactor/client/methods.rb