lib/celluloid/io/common_methods.rb in celluloid-io-0.12.1 vs lib/celluloid/io/common_methods.rb in celluloid-io-0.13.0.pre

- old
+ new

@@ -2,11 +2,11 @@ module IO # Common implementations of methods originall from the IO class module CommonMethods # Are we inside of a Celluloid::IO actor? def evented? - actor = Thread.current[:actor] + actor = Thread.current[:celluloid_actor] actor && actor.mailbox.is_a?(Celluloid::IO::Mailbox) end # Wait until the current object is readable def wait_readable @@ -27,45 +27,45 @@ end # Request exclusive control for a particular operation # Type should be one of :r (read) or :w (write) def acquire_ownership(type) - return unless Thread.current[:actor] + return unless Thread.current[:celluloid_actor] case type when :r ivar = :@read_owner when :w ivar = :@write_owner else raise ArgumentError, "invalid ownership type: #{type}" end # Celluloid needs a better API here o_O - Thread.current[:actor].wait(self) while instance_variable_get(ivar) + Thread.current[:celluloid_actor].wait(self) while instance_variable_defined?(ivar) && instance_variable_get(ivar) instance_variable_set(ivar, Task.current) end # Release ownership for a particular operation # Type should be one of :r (read) or :w (write) def release_ownership(type) - return unless Thread.current[:actor] + return unless Thread.current[:celluloid_actor] case type when :r ivar = :@read_owner when :w ivar = :@write_owner else raise ArgumentError, "invalid ownership type: #{type}" end - raise "not owner" unless instance_variable_get(ivar) == Task.current + raise "not owner" unless instance_variable_defined?(ivar) && instance_variable_get(ivar) == Task.current instance_variable_set(ivar, nil) - Thread.current[:actor].signal(self) + Thread.current[:celluloid_actor].signal(self) end def read(length = nil, buffer = nil) - buffer ||= '' + buffer ||= ''.force_encoding(Encoding::ASCII_8BIT) remaining = length acquire_ownership :r begin if length @@ -95,11 +95,11 @@ buffer end def readpartial(length, buffer = nil) - buffer ||= '' + buffer ||= ''.force_encoding(Encoding::ASCII_8BIT) begin read_nonblock(length, buffer) rescue ::IO::WaitReadable wait_readable @@ -134,9 +134,13 @@ release_ownership :w end total_written end - alias_method :<<, :write + + def <<(string) + write string + self + end end end end