1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Ignore failure to set nonblock mode. (#6524)

This commit is contained in:
Samuel Williams 2022-10-11 10:18:20 +13:00 committed by GitHub
parent 1a7e7bb2d1
commit 1bafa4a59b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
Notes: git 2022-10-11 06:18:45 +09:00
Merged-By: ioquatix <samuel@codeotaku.com>
2 changed files with 18 additions and 2 deletions

4
io.c
View file

@ -3571,7 +3571,7 @@ io_read_nonblock(rb_execution_context_t *ec, VALUE io, VALUE length, VALUE str,
n = read_buffered_data(RSTRING_PTR(str), len, fptr);
if (n <= 0) {
rb_io_set_nonblock(fptr);
rb_fd_set_nonblock(fptr->fd);
shrinkable |= io_setstrbuf(&str, len);
iis.fptr = fptr;
iis.nonblock = 1;
@ -3618,7 +3618,7 @@ io_write_nonblock(rb_execution_context_t *ec, VALUE io, VALUE str, VALUE ex)
if (io_fflush(fptr) < 0)
rb_sys_fail_on_write(fptr);
rb_io_set_nonblock(fptr);
rb_fd_set_nonblock(fptr->fd);
n = write(fptr->fd, RSTRING_PTR(str), RSTRING_LEN(str));
RB_GC_GUARD(str);

View file

@ -1597,6 +1597,22 @@ class TestIO < Test::Unit::TestCase
end
end
def test_read_nonblock_file
make_tempfile do |path|
File.open(path, 'r') do |file|
file.read_nonblock(4)
end
end
end
def test_write_nonblock_file
make_tempfile do |path|
File.open(path, 'w') do |file|
file.write_nonblock("Ruby")
end
end
end
def test_write_nonblock_simple_no_exceptions
pipe(proc do |w|
w.write_nonblock('1', exception: false)