Sha256: 9ae949c99931596640b9ceba3d8a3a5c6aedc1ff822eea75a9a39c2b1fe91e5c

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

# -*- encoding: binary -*-
# :enddoc:

# this is used to augment Kgio::Socket and Kgio::Pipe-enhanced classes
# for use with Rainbows!  Do no use this directly, see
# Rainbows::Fiber::IO::Pipe and Rainbows::Fiber::IO::Socket instead.
module Rainbows::Fiber::IO::Methods
  RD = Rainbows::Fiber::RD
  WR = Rainbows::Fiber::WR
  ZZ = Rainbows::Fiber::ZZ
  attr_accessor :f

  def read_expire
    ZZ[Fiber.current] = super
  end

  # for wrapping output response bodies
  def each
    if buf = kgio_read(16384)
      yield buf
      yield buf while kgio_read(16384, buf)
    end
    self
  end

  def close
    fd = fileno
    RD[fd] = WR[fd] = nil
    super
  end

  def kgio_wait_readable
    fd = fileno
    @f = Fiber.current
    RD[fd] = self
    Fiber.yield
    ZZ.delete @f
    RD[fd] = nil
  end

  def kgio_wait_writable
    fd = fileno
    @f = Fiber.current
    WR[fd] = self
    Fiber.yield
    WR[fd] = nil
  end

  def self.included(klass)
    if klass.method_defined?(:kgio_write)
      klass.__send__(:alias_method, :write, :kgio_write)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rainbows-4.0.0 lib/rainbows/fiber/io/methods.rb