Merge pull request #227 from vibe-d/eventcore_fileio_cancel_workaround

Work around critical issue in eventcore's cancelRead/cancelWrite.
This commit is contained in:
Leonid Kramer 2020-09-18 22:58:34 +02:00 committed by GitHub
commit 5f0bac04f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -607,9 +607,11 @@ struct FileStream {
size_t read(ubyte[] dst, IOMode mode) size_t read(ubyte[] dst, IOMode mode)
{ {
auto res = asyncAwait!(FileIOCallback, // NOTE: cancelRead is currently not behaving as specified and cannot
cb => eventDriver.files.read(m_fd, ctx.ptr, dst, mode, cb), // be relied upon. For this reason, we MUST use the uninterruptible
cb => eventDriver.files.cancelRead(m_fd) // version of asyncAwait here!
auto res = asyncAwaitUninterruptible!(FileIOCallback,
cb => eventDriver.files.read(m_fd, ctx.ptr, dst, mode, cb)
); );
ctx.ptr += res[2]; ctx.ptr += res[2];
enforce(res[1] == IOStatus.ok, "Failed to read data from disk."); enforce(res[1] == IOStatus.ok, "Failed to read data from disk.");
@ -624,9 +626,11 @@ struct FileStream {
size_t write(in ubyte[] bytes, IOMode mode) size_t write(in ubyte[] bytes, IOMode mode)
{ {
auto res = asyncAwait!(FileIOCallback, // NOTE: cancelWrite is currently not behaving as specified and cannot
cb => eventDriver.files.write(m_fd, ctx.ptr, bytes, mode, cb), // be relied upon. For this reason, we MUST use the uninterruptible
cb => eventDriver.files.cancelWrite(m_fd) // version of asyncAwait here!
auto res = asyncAwaitUninterruptible!(FileIOCallback,
cb => eventDriver.files.write(m_fd, ctx.ptr, bytes, mode, cb)
); );
ctx.ptr += res[2]; ctx.ptr += res[2];
if (ctx.ptr > ctx.size) ctx.size = ctx.ptr; if (ctx.ptr > ctx.size) ctx.size = ctx.ptr;