aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2021-10-07 22:47:36 +0000
committerJason A. Donenfeld <Jason@zx2c4.com>2021-10-11 16:12:09 +0000
commitfa6b6dfc789fdd18f1a35cf997ab1e21c7322fc5 (patch)
tree47384e071582c074264605ac91860e16fffe93a4
parentapi: adapter: ensure file handle opens on win7 (diff)
downloadwireguard-nt-fa6b6dfc789fdd18f1a35cf997ab1e21c7322fc5.tar.xz
wireguard-nt-fa6b6dfc789fdd18f1a35cf997ab1e21c7322fc5.zip
api: unify remaining poll loop forms
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--api/adapter_win7.h4
-rw-r--r--api/driver.c10
2 files changed, 10 insertions, 4 deletions
diff --git a/api/adapter_win7.h b/api/adapter_win7.h
index 400af2c..065b2d1 100644
--- a/api/adapter_win7.h
+++ b/api/adapter_win7.h
@@ -25,9 +25,9 @@ WaitForInterfaceWin7(_In_ HDEVINFO DevInfo, _In_ SP_DEVINFO_DATA *DevInfoData, _
HKEY Key = INVALID_HANDLE_VALUE;
HANDLE FileHandle = INVALID_HANDLE_VALUE;
BOOLEAN Ret = FALSE;
- for (int i = 0; i < 1500; ++i)
+ for (DWORD Tries = 0; Tries < 1500; ++Tries)
{
- if (i)
+ if (Tries)
Sleep(10);
if (Key == INVALID_HANDLE_VALUE)
Key = SetupDiOpenDevRegKey(DevInfo, DevInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DRV, KEY_QUERY_VALUE);
diff --git a/api/driver.c b/api/driver.c
index 05756d4..818e26d 100644
--- a/api/driver.c
+++ b/api/driver.c
@@ -406,8 +406,14 @@ DWORD WINAPI WireGuardGetRunningDriverVersion(VOID)
static BOOL EnsureWireGuardUnloaded(VOID)
{
BOOL Loaded;
- for (int i = 0; (Loaded = MaybeGetRunningDriverVersion(TRUE) != 0) != FALSE && i < 300; ++i)
- Sleep(50);
+ for (DWORD Tries = 0; Tries < 1500; ++Tries)
+ {
+ if (Tries)
+ Sleep(50);
+ Loaded = MaybeGetRunningDriverVersion(TRUE) != 0;
+ if (!Loaded)
+ break;
+ }
return !Loaded;
}