Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1d03e20a2223
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ced0230cf3db
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Oct 2, 2015

  1. Copy the full SHA
    bd20526 View commit details
  2. Copy the full SHA
    ced0230 View commit details
Showing with 50 additions and 9 deletions.
  1. +4 −4 kernel/bootstrap/io.rb
  2. +46 −5 kernel/common/io.rb
8 changes: 4 additions & 4 deletions kernel/bootstrap/io.rb
Original file line number Diff line number Diff line change
@@ -70,10 +70,10 @@ def write2(str)
# raise PrimitiveFailure, "IO#read_if_available primitive failed"
# end

def raw_write(str)
Rubinius.primitive :io_write_nonblock
raise PrimitiveFailure, "IO#write_nonblock primitive failed"
end
# def raw_write(str)
# Rubinius.primitive :io_write_nonblock
# raise PrimitiveFailure, "IO#write_nonblock primitive failed"
# end

def reopen_io(other)
Rubinius.primitive :io_reopen
51 changes: 46 additions & 5 deletions kernel/common/io.rb
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ class EAGAINWaitWritable < Errno::EAGAIN
F_SETFD = Rubinius::Config['rbx.platform.fcntl.F_SETFD']
FD_CLOEXEC = Rubinius::Config['rbx.platform.fcntl.FD_CLOEXEC']
O_CLOEXEC = Rubinius::Config['rbx.platform.file.O_CLOEXEC']
O_NONBLOCK = Rubinius::Config['rbx.platform.file.O_NONBLOCK']

# Not available on all platforms, so these constants may be nil
POSIX_FADV_NORMAL = Rubinius::Config['rbx.platform.advise.POSIX_FADV_NORMAL']
@@ -432,14 +433,32 @@ def seek_positioning

def set_mode
if IO::F_GETFL
acc_mode = FFI::Platform::POSIX.fcntl(@descriptor, IO::F_GETFL, 0)
Errno.handle("failed") if acc_mode < 0
if FFI.called_failed?(acc_mode = FFI::Platform::POSIX.fcntl(@descriptor, IO::F_GETFL, 0))
Errno.handle("failed")
end
else
acc_mode = 0
end

@mode = acc_mode
end

def set_nonblock
if IO::F_GETFL
if FFI.call_failed?(flags = FFI::Platform::POSIX.fcntl(@descriptor, IO::F_GETFL, 0))
Errno.handle("fcntl(2) failed")
end
else
flags = 0
end

if (flags & O_NONBLOCK) == 0
flags |= O_NONBLOCK
if FFI.call_failed?(flags = FFI::Platform::POSIX.fcntl(@descriptor, IO::F_SETFL, flags))
Errno.handle("fcntl(2) failed")
end
end
end

def ftruncate(offset)
ensure_open
@@ -587,6 +606,30 @@ def reset_positioning(*args)
@unget_buffer = []
super
end

def write_nonblock(str)
buffer_reset
set_nonblock

buf_size = str.bytesize
left = buf_size

buffer = FFI::MemoryPointer.new(left)
buffer.write_string(str)
error = false

if left > 0
if FFI.call_failed?(bytes_written = FFI::Platform::POSIX.write(@descriptor, buffer, left))
Errno.handle("write_nonblock")
end

left -= bytes_written
buffer += bytes_written
@offset += bytes_written
end

return(buf_size - left)
end

def unget(byte)
@offset -= 1
@@ -3153,9 +3196,7 @@ def write_nonblock(data)
data = String data
return 0 if data.bytesize == 0

# @ibuffer.unseek!(self) unless @sync

raw_write(data)
@fd.write_nonblock(data)
end

def close