parent
eb91c664dc
commit
5f77f9bea6
Notes:
git
2025-03-23 00:42:21 +00:00
Merged-By: ioquatix <samuel@codeotaku.com>
10
io.c
10
io.c
@ -1181,8 +1181,14 @@ io_internal_wait(VALUE thread, rb_io_t *fptr, int error, int events, struct time
|
||||
return -1;
|
||||
}
|
||||
|
||||
errno = error;
|
||||
return -1;
|
||||
// If there was an error BEFORE we started waiting, return it:
|
||||
if (error) {
|
||||
errno = error;
|
||||
return -1;
|
||||
} else {
|
||||
// Otherwise, whatever error was generated by `nogvl_wait_for` is the one we want:
|
||||
return ready;
|
||||
}
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
@ -4373,4 +4373,30 @@ __END__
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_blocking_timeout
|
||||
assert_separately([], <<~'RUBY')
|
||||
IO.pipe do |r, w|
|
||||
trap(:INT) do
|
||||
w.puts "INT"
|
||||
end
|
||||
|
||||
main = Thread.current
|
||||
thread = Thread.new do
|
||||
# Wait until the main thread has entered `$stdin.gets`:
|
||||
Thread.pass until main.status == 'sleep'
|
||||
|
||||
# Cause an interrupt while handling `$stdin.gets`:
|
||||
Process.kill :INT, $$
|
||||
end
|
||||
|
||||
r.timeout = 1
|
||||
assert_equal("INT", r.gets.chomp)
|
||||
rescue IO::TimeoutError
|
||||
# Ignore - some platforms don't support interrupting `gets`.
|
||||
ensure
|
||||
thread&.join
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user