You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The nonblock allows the syswrite call to write only as much as there is system-level buffer room and then return. At this point the buffer is full, so the subsequent copy from r to w2 should block attempting to write the rest of the bytes.
The MRI implementation of copy_stream is very complex, so I'm not sure yet if this is done intentionally. It's likely using blocking write logic to loop until all bytes have been copied.
This is not a particularly critical bug; it will be rare that someone wants to have a stream be both nonblocking and do blocking copy_stream calls against it, but I file it here for posterity.
This is, incidentally, the cause of TestIO#test_copy_stream_pipe_nonblock failing to succeed; the copy_stream logic sees a full system buffer and nonblock and returns 0 before the read thread has a chance to empty the buffer. MRI blocks here and waits for the read thread.
ifhave_nonblock?deftest_copy_stream_pipe_nonblockmkcdtmpdir{with_read_pipe("abc"){|r1|
assert_equal("a",r1.getc)with_pipe{|r2,w2|
beginw2.nonblock=truerescueErrno::EBADFskip"nonblocking IO for pipe is not implemented"breakends=w2.syswrite("a" * 100000)t=Thread.new{sleep0.1;r2.read}ret=IO.copy_stream(r1,w2)w2.closeassert_equal(2,ret)assert_equal("a" * s + "bc",t.value)}}}endend
The text was updated successfully, but these errors were encountered:
The following snippit of code should always block in the copy_stream call:
The nonblock allows the syswrite call to write only as much as there is system-level buffer room and then return. At this point the buffer is full, so the subsequent copy from
r
tow2
should block attempting to write the rest of the bytes.The MRI implementation of copy_stream is very complex, so I'm not sure yet if this is done intentionally. It's likely using blocking write logic to loop until all bytes have been copied.
This is not a particularly critical bug; it will be rare that someone wants to have a stream be both nonblocking and do blocking copy_stream calls against it, but I file it here for posterity.
This is, incidentally, the cause of TestIO#test_copy_stream_pipe_nonblock failing to succeed; the copy_stream logic sees a full system buffer and nonblock and returns 0 before the read thread has a chance to empty the buffer. MRI blocks here and waits for the read thread.
The text was updated successfully, but these errors were encountered: