mirror of
https://github.com/solemnwarning/ipxwrapper
synced 2024-12-30 16:45:37 +01:00
Use GetTickCount64() for connect timeouts where available.
This commit is contained in:
parent
b5a92e00ad
commit
e5315890fd
@ -1,5 +1,5 @@
|
||||
/* ipxwrapper - Library functions
|
||||
* Copyright (C) 2008-2013 Daniel Collins <solemnwarning@solemnwarning.net>
|
||||
* Copyright (C) 2008-2014 Daniel Collins <solemnwarning@solemnwarning.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 as published by
|
||||
@ -48,6 +48,9 @@ main_config_t main_config;
|
||||
|
||||
static CRITICAL_SECTION sockets_cs;
|
||||
|
||||
typedef ULONGLONG WINAPI (*GetTickCount64_t)(void);
|
||||
static HMODULE kernel32 = NULL;
|
||||
|
||||
static void init_cs(CRITICAL_SECTION *cs)
|
||||
{
|
||||
if(!InitializeCriticalSectionAndSpinCount(cs, 0x80000000))
|
||||
@ -121,6 +124,12 @@ BOOL WINAPI DllMain(HINSTANCE me, DWORD why, LPVOID res)
|
||||
unload_dlls();
|
||||
|
||||
log_close();
|
||||
|
||||
if(kernel32)
|
||||
{
|
||||
FreeLibrary(kernel32);
|
||||
kernel32 = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
@ -157,3 +166,21 @@ void unlock_sockets(void)
|
||||
{
|
||||
LeaveCriticalSection(&sockets_cs);
|
||||
}
|
||||
|
||||
uint64_t get_ticks(void)
|
||||
{
|
||||
static GetTickCount64_t GetTickCount64 = NULL;
|
||||
|
||||
if(!kernel32 && (kernel32 = LoadLibrary("kernel32.dll")))
|
||||
{
|
||||
GetTickCount64 = (GetTickCount64_t)(GetProcAddress(kernel32, "GetTickCount64"));
|
||||
}
|
||||
|
||||
if(GetTickCount64)
|
||||
{
|
||||
return GetTickCount64();
|
||||
}
|
||||
else{
|
||||
return GetTickCount();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* ipxwrapper - Library header
|
||||
* Copyright (C) 2008-2013 Daniel Collins <solemnwarning@solemnwarning.net>
|
||||
* Copyright (C) 2008-2014 Daniel Collins <solemnwarning@solemnwarning.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 as published by
|
||||
@ -131,6 +131,7 @@ extern main_config_t main_config;
|
||||
ipx_socket *get_socket(SOCKET sockfd);
|
||||
void lock_sockets(void);
|
||||
void unlock_sockets(void);
|
||||
uint64_t get_ticks(void);
|
||||
|
||||
void add_self_to_firewall(void);
|
||||
|
||||
|
@ -1635,13 +1635,11 @@ static int _connect_spx(ipx_socket *sock, struct sockaddr_ipx *ipxaddr)
|
||||
*
|
||||
* BUG: Batch may time out or wait (effectively) forever if the
|
||||
* batch is sent just before the system tick count rolls over.
|
||||
*
|
||||
* TODO: Use GetTickCount64() if available.
|
||||
*/
|
||||
|
||||
DWORD wait_until = GetTickCount() + (IPX_CONNECT_TIMEOUT / IPX_CONNECT_TRIES) * 1000;
|
||||
uint64_t wait_until = get_ticks() + (IPX_CONNECT_TIMEOUT / IPX_CONNECT_TRIES) * 1000;
|
||||
|
||||
for(DWORD now; (now = GetTickCount()) < wait_until;)
|
||||
for(uint64_t now; (now = get_ticks()) < wait_until;)
|
||||
{
|
||||
/* Release the socket table in case the remote address
|
||||
* in question is in the same process and we block the
|
||||
|
Loading…
x
Reference in New Issue
Block a user