lib/rainbows/fiber/io.rb in rainbows-2.0.1 vs lib/rainbows/fiber/io.rb in rainbows-2.1.0

- old
+ new

@@ -16,11 +16,11 @@ class << self alias :[] :new end # :startdoc: - # needed to write errors with + # no longer used internally within Rainbows!, only for compatibility def write_nonblock(buf) @to_io.write_nonblock(buf) end def kgio_addr @@ -57,44 +57,42 @@ end end while true else begin (rv = @to_io.write_nonblock(buf)) == buf.bytesize and return - buf = byte_slice(buf, rv..-1) + buf = byte_slice(buf, rv) rescue Errno::EAGAIN kgio_wait_writable end while true end end - def byte_slice(buf, range) # :nodoc: - if buf.encoding != Encoding::BINARY - buf.dup.force_encoding(Encoding::BINARY)[range] - else - buf[range] - end + def byte_slice(buf, start) # :nodoc: + buf.encoding == Encoding::BINARY or + buf = buf.dup.force_encoding(Encoding::BINARY) + buf.slice(start, buf.size) end # used for reading headers (respecting keepalive_timeout) def timed_read(buf) expire = nil if @to_io.respond_to?(:kgio_tryread) begin case rv = @to_io.kgio_tryread(16384, buf) when :wait_readable return if expire && expire < Time.now - expire ||= Time.now + G.kato + expire ||= read_expire kgio_wait_readable else return rv end end while true else begin return @to_io.read_nonblock(16384, buf) rescue Errno::EAGAIN return if expire && expire < Time.now - expire ||= Time.now + G.kato + expire ||= read_expire kgio_wait_readable end while true end end