Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions lib/io/stream/buffered.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,26 @@ def sysclose
end
end

def syswrite(buffer)
# This fails due to re-entrancy issues with a concurrent call to `sysclose`.
# return @io.write(buffer)

while true
result = @io.write_nonblock(buffer, exception: false)

case result
when :wait_readable
@io.wait_readable(@io.timeout) or raise ::IO::TimeoutError, "read timeout"
when :wait_writable
@io.wait_writable(@io.timeout) or raise ::IO::TimeoutError, "write timeout"
else
if result == buffer.bytesize
return
if RUBY_VERSION >= "3.3"
def syswrite(buffer)
return @io.write(buffer)
end
else
def syswrite(buffer)
while true
result = @io.write_nonblock(buffer, exception: false)

case result
when :wait_readable
@io.wait_readable(@io.timeout) or raise ::IO::TimeoutError, "read timeout"
when :wait_writable
@io.wait_writable(@io.timeout) or raise ::IO::TimeoutError, "write timeout"
else
buffer = buffer.byteslice(result, buffer.bytesize)
if result == buffer.bytesize
return
else
buffer = buffer.byteslice(result, buffer.bytesize)
end
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions releases.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Releases

## Unreleased

- On Ruby v3.3+, use `IO#write` directly instead of `IO#write_nonblock`, for better performance.

## v0.7.0

- Split stream functionality into separate `Readable` and `Writable` modules for better modularity and composition.
Expand Down
Loading