module Celluloid::IO

Actors with evented IO support

Constants

BLOCK_SIZE

Default size to read from or write to the stream for buffer operations

VERSION

Public Class Methods

copy_stream(src, dst, copy_length = nil, src_offset = nil) click to toggle source
# File lib/celluloid/io.rb, line 39
def self.copy_stream(src, dst, copy_length = nil, src_offset = nil)
  fail NotImplementedError, "length/offset not supported" if copy_length || src_offset

  src, dst = try_convert(src), try_convert(dst)

  # FIXME: this always goes through the reactor, and can block on file I/O
  while data = src.read(BLOCK_SIZE)
    dst << data
  end
end
evented?() click to toggle source
# File lib/celluloid/io.rb, line 30
def self.evented?
  actor = Thread.current[:celluloid_actor]
  actor && actor.mailbox.is_a?(Celluloid::IO::Mailbox)
end
included(klass) click to toggle source
# File lib/celluloid/io.rb, line 25
def self.included(klass)
  klass.send :include, Celluloid
  klass.mailbox_class Celluloid::IO::Mailbox
end
try_convert(src) click to toggle source
# File lib/celluloid/io.rb, line 35
def self.try_convert(src)
  ::IO.try_convert(src)
end
wait_readable(io) click to toggle source
# File lib/celluloid/io.rb, line 50
def wait_readable(io)
  io = io.to_io
  if IO.evented?
    mailbox = Thread.current[:celluloid_mailbox]
    mailbox.reactor.wait_readable(io)
  else
    Kernel.select([io])
  end
  nil
end
wait_writable(io) click to toggle source
# File lib/celluloid/io.rb, line 62
def wait_writable(io)
  io = io.to_io
  if IO.evented?
    mailbox = Thread.current[:celluloid_mailbox]
    mailbox.reactor.wait_writable(io)
  else
    Kernel.select([], [io])
  end
  nil
end

Private Instance Methods

wait_readable(io) click to toggle source
# File lib/celluloid/io.rb, line 50
def wait_readable(io)
  io = io.to_io
  if IO.evented?
    mailbox = Thread.current[:celluloid_mailbox]
    mailbox.reactor.wait_readable(io)
  else
    Kernel.select([io])
  end
  nil
end
wait_writable(io) click to toggle source
# File lib/celluloid/io.rb, line 62
def wait_writable(io)
  io = io.to_io
  if IO.evented?
    mailbox = Thread.current[:celluloid_mailbox]
    mailbox.reactor.wait_writable(io)
  else
    Kernel.select([], [io])
  end
  nil
end