Module: Celluloid::IO

Defined in:
lib/celluloid/io.rb,
lib/celluloid/io/stream.rb,
lib/celluloid/io/mailbox.rb,
lib/celluloid/io/reactor.rb,
lib/celluloid/io/version.rb,
lib/celluloid/io/tcp_server.rb,
lib/celluloid/io/tcp_socket.rb,
lib/celluloid/io/ssl_socket.rb,
lib/celluloid/io/udp_socket.rb,
lib/celluloid/io/ssl_server.rb,
lib/celluloid/io/unix_server.rb,
lib/celluloid/io/unix_socket.rb,
lib/celluloid/io/dns_resolver.rb

Overview

Actors with evented IO support

Defined Under Namespace

Classes: DNSResolver, Mailbox, Reactor, SSLServer, SSLSocket, Stream, TCPServer, TCPSocket, UDPSocket, UNIXServer, UNIXSocket

Constant Summary

BLOCK_SIZE =

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

1024 * 16
VERSION =
"0.16.1"

Class Method Summary (collapse)

Class Method Details

+ (Object) copy_stream(src, dst, copy_length = nil, src_offset = nil)

Raises:

  • (NotImplementedError)


38
39
40
41
42
43
44
45
46
47
# File 'lib/celluloid/io.rb', line 38

def self.copy_stream(src, dst, copy_length = nil, src_offset = nil)
  raise 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

+ (Boolean) evented?



29
30
31
32
# File 'lib/celluloid/io.rb', line 29

def self.evented?
  actor = Thread.current[:celluloid_actor]
  actor && actor.mailbox.is_a?(Celluloid::IO::Mailbox)
end

+ (Object) included(klass)



24
25
26
27
# File 'lib/celluloid/io.rb', line 24

def self.included(klass)
  klass.send :include, Celluloid
  klass.mailbox_class Celluloid::IO::Mailbox
end

+ (Object) try_convert(src)



34
35
36
# File 'lib/celluloid/io.rb', line 34

def self.try_convert(src)
  ::IO.try_convert(src)
end

+ (Object) wait_readable(io)



49
50
51
52
53
54
55
56
57
58
# File 'lib/celluloid/io.rb', line 49

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

+ (Object) wait_writable(io)



61
62
63
64
65
66
67
68
69
70
# File 'lib/celluloid/io.rb', line 61

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