From 3261b460c81523d9a86f4eed22f5af6bb1614671 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Wed, 2 Sep 2026 10:23:43 -0300 Subject: [PATCH] Fix Windows build. --- src/eepp/system/ipc.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/eepp/system/ipc.cpp b/src/eepp/system/ipc.cpp index c57ce7f9f..99312fe4f 100644 --- a/src/eepp/system/ipc.cpp +++ b/src/eepp/system/ipc.cpp @@ -178,6 +178,14 @@ bool endpointOwned( const wchar_t* ownershipName ) { return true; } +void cancelSynchronousIO( HANDLE thread ) { + using CancelSynchronousIOFn = BOOL( WINAPI* )( HANDLE ); + static const auto cancel = reinterpret_cast( + GetProcAddress( GetModuleHandleW( L"kernel32.dll" ), "CancelSynchronousIo" ) ); + if ( cancel != nullptr ) + cancel( thread ); +} + IPC::Status windowsErrorStatus( DWORD error ) { if ( error == ERROR_FILE_NOT_FOUND || error == ERROR_PATH_NOT_FOUND ) return IPC::Status::NotFound; @@ -491,7 +499,7 @@ void IPC::close() { #if EE_PLATFORM == EE_PLATFORM_WIN { std::lock_guard lock( mImpl->handlesMutex ); - CancelSynchronousIo( reinterpret_cast( mImpl->worker.native_handle() ) ); + cancelSynchronousIO( reinterpret_cast( mImpl->worker.native_handle() ) ); HANDLE wake = CreateFileW( mImpl->nativeName.data(), GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr ); if ( wake != INVALID_HANDLE_VALUE ) @@ -555,7 +563,7 @@ IPC::Status IPC::send( std::string_view endpoint, const void* data, std::size_t const NativeName name = nativeName( L"\\\\.\\pipe\\eepp-", hash ); const NativeName ownership = nativeName( L"Local\\eepp-ipc-owner-", hash ); const Uint64 timeoutMs = static_cast( eemax( 0, timeout.asMilliseconds() ) ); - const Uint64 deadline = GetTickCount64() + timeoutMs; + const Uint64 startTime = Sys::getTicks(); HANDLE pipe; while ( true ) { pipe = CreateFileW( name.data(), GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, @@ -567,7 +575,7 @@ IPC::Status IPC::send( std::string_view endpoint, const void* data, std::size_t error == ERROR_FILE_NOT_FOUND && endpointOwned( ownership.data() ); if ( error != ERROR_PIPE_BUSY && error != ERROR_SEM_TIMEOUT && !transitioning ) return windowsErrorStatus( error ); - if ( GetTickCount64() >= deadline ) + if ( Sys::getTicks() - startTime >= timeoutMs ) return Status::Timeout; Sleep( 1 ); }