mirror of
https://github.com/decompals/wibo.git
synced 2025-12-13 15:16:27 +00:00
Fix GetOverlappedResult without event & improve overlapped handling
This commit is contained in:
@@ -2,24 +2,32 @@
|
||||
|
||||
#include "context.h"
|
||||
#include "errors.h"
|
||||
#include "internal.h"
|
||||
#include "overlapped_util.h"
|
||||
#include "synchapi.h"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
namespace kernel32 {
|
||||
|
||||
BOOL WIN_FUNC GetOverlappedResult(HANDLE hFile, LPOVERLAPPED lpOverlapped, LPDWORD lpNumberOfBytesTransferred,
|
||||
BOOL bWait) {
|
||||
HOST_CONTEXT_GUARD();
|
||||
DEBUG_LOG("GetOverlappedResult(%p, %p, %p, %d)\n", hFile, lpOverlapped, lpNumberOfBytesTransferred, bWait);
|
||||
(void)hFile;
|
||||
if (!lpOverlapped) {
|
||||
wibo::lastError = ERROR_INVALID_PARAMETER;
|
||||
return FALSE;
|
||||
}
|
||||
if (bWait && lpOverlapped->Internal == STATUS_PENDING &&
|
||||
kernel32::detail::shouldSignalOverlappedEvent(lpOverlapped)) {
|
||||
|
||||
if (bWait && lpOverlapped->Internal == STATUS_PENDING) {
|
||||
if (HANDLE waitHandle = kernel32::detail::normalizedOverlappedEventHandle(lpOverlapped)) {
|
||||
WaitForSingleObject(waitHandle, INFINITE);
|
||||
} else if (auto file = wibo::handles().getAs<FileObject>(hFile)) {
|
||||
std::unique_lock lk(file->m);
|
||||
file->overlappedCv.wait(lk, [&] { return lpOverlapped->Internal != STATUS_PENDING; });
|
||||
} else {
|
||||
wibo::lastError = ERROR_INVALID_HANDLE;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user