Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle cases where ReadFile/WriteFile may complete synchronously #161

Closed
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
32 changes: 16 additions & 16 deletions vrs/AsyncDiskFileChunk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,30 +172,30 @@ struct AsyncWindowsHandle {
return readNotWrite ? DISKFILE_NOT_ENOUGH_DATA : DISKFILE_PARTIAL_WRITE_ERROR;
}

OVERLAPPED ov;

ov.hEvent = 0;
// N.B. this does not create an hEvent for the OVERLAPPED structure, instead using the file
// handle. This is only a valid thing to do if there are NO other IO operations occuring during
// this one. The calls to flushWriteBuffer() before calling this ensures this is the case.
OVERLAPPED ov = {};
ov.Offset = (DWORD)offset;
ov.OffsetHigh = (DWORD)(offset >> 32);

DWORD dwNumberOfBytesTransferred = 0;
bool success = false;
if (readNotWrite) {
if (ReadFile(h_, buf, dwToXfer, nullptr, &ov)) {
return SUCCESS;
}
success = ReadFile(h_, buf, dwToXfer, &dwNumberOfBytesTransferred, &ov);
} else {
if (WriteFile(h_, buf, dwToXfer, nullptr, &ov)) {
return SUCCESS;
}
success = WriteFile(h_, buf, dwToXfer, &dwNumberOfBytesTransferred, &ov);
}

int error = GetLastError();
if (error != ERROR_IO_PENDING) {
return error;
}
if (!success) {
int error = GetLastError();
if (error != ERROR_IO_PENDING) {
return error;
}

DWORD dwNumberOfBytesTransferred;
if (!GetOverlappedResult(h_, &ov, &dwNumberOfBytesTransferred, TRUE)) {
return GetLastError();
if (!GetOverlappedResult(h_, &ov, &dwNumberOfBytesTransferred, TRUE)) {
return GetLastError();
}
}

outSize = dwNumberOfBytesTransferred;
Expand Down
3 changes: 0 additions & 3 deletions vrs/test/file_tests/DeviceSimulatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

#include <vrs/DiskFile.h>
#include <vrs/RecordFileReader.h>
#include <vrs/os/Platform.h>
#include <vrs/os/Utils.h>

#include <vrs/test/helpers/VRSTestsHelpers.h>
Expand Down Expand Up @@ -128,7 +127,6 @@ TEST_F(DeviceSimulator, multiThreadAsyncAioNotDirect) {
deleteChunkedFile(testPath);
}

#if IS_VRS_FB_INTERNAL() || !IS_WINDOWS_PLATFORM() // avoid OSS/Windows
TEST_F(DeviceSimulator, multiThreadAsyncSync) {
const string testPath = os::getTempFolder() + "MultiThreadAsyncSync.vrs";

Expand All @@ -140,7 +138,6 @@ TEST_F(DeviceSimulator, multiThreadAsyncSync) {

deleteChunkedFile(testPath);
}
#endif

TEST_F(DeviceSimulator, multiThreadAsyncPsync) {
const string testPath = os::getTempFolder() + "MultiThreadAsyncPsync.vrs";
Expand Down
Loading