fix kFirstClientTimeoutMs 30s
This commit is contained in:
@@ -19,7 +19,7 @@ static LONG g_seen_client = 0;
|
|||||||
static LONG64 g_session_id = 0;
|
static LONG64 g_session_id = 0;
|
||||||
static std::mutex g_clients_mutex;
|
static std::mutex g_clients_mutex;
|
||||||
static std::vector<std::shared_ptr<ClientInfo>> g_clients;
|
static std::vector<std::shared_ptr<ClientInfo>> g_clients;
|
||||||
static constexpr DWORD kFirstClientTimeoutMs = 3000;
|
static constexpr DWORD kFirstClientTimeoutMs = 30000;
|
||||||
|
|
||||||
|
|
||||||
static void ExitServerProcess(UINT exit_code)
|
static void ExitServerProcess(UINT exit_code)
|
||||||
@@ -335,18 +335,36 @@ static bool DispatchCommand(HANDLE pipe, const std::shared_ptr<ClientInfo>& clie
|
|||||||
|
|
||||||
static DWORD WINAPI FirstClientTimeoutProc(LPVOID)
|
static DWORD WINAPI FirstClientTimeoutProc(LPVOID)
|
||||||
{
|
{
|
||||||
DWORD wait = WaitForSingleObject(g_exit_event, kFirstClientTimeoutMs);
|
if (kFirstClientTimeoutMs != INFINITE)
|
||||||
|
{
|
||||||
|
DWORD wait = WaitForSingleObject(
|
||||||
|
g_exit_event,
|
||||||
|
kFirstClientTimeoutMs);
|
||||||
|
|
||||||
if (wait == WAIT_TIMEOUT &&
|
if (wait == WAIT_TIMEOUT &&
|
||||||
InterlockedCompareExchange(&g_seen_client, 0, 0) == 0)
|
InterlockedCompareExchange(&g_seen_client, 0, 0) == 0)
|
||||||
{
|
{
|
||||||
//printf("[server] no client connected in %lu ms, server shutdown\n", kFirstClientTimeoutMs);
|
|
||||||
fflush(stdout);
|
|
||||||
RequestShutdown("first client timeout");
|
RequestShutdown("first client timeout");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//static DWORD WINAPI FirstClientTimeoutProc(LPVOID)
|
||||||
|
//{
|
||||||
|
// DWORD wait = WaitForSingleObject(g_exit_event, kFirstClientTimeoutMs);
|
||||||
|
// if (wait == WAIT_TIMEOUT &&
|
||||||
|
// InterlockedCompareExchange(&g_seen_client, 0, 0) == 0)
|
||||||
|
// {
|
||||||
|
// //printf("[server] no client connected in %lu ms, server shutdown\n", kFirstClientTimeoutMs);
|
||||||
|
// fflush(stdout);
|
||||||
|
// RequestShutdown("first client timeout");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return 0;
|
||||||
|
//}
|
||||||
|
|
||||||
static DWORD WINAPI MonitorThreadProc(LPVOID)
|
static DWORD WINAPI MonitorThreadProc(LPVOID)
|
||||||
{
|
{
|
||||||
while (WaitForSingleObject(g_exit_event, kHeartbeatIntervalMs) == WAIT_TIMEOUT)
|
while (WaitForSingleObject(g_exit_event, kHeartbeatIntervalMs) == WAIT_TIMEOUT)
|
||||||
@@ -477,6 +495,37 @@ static DWORD WINAPI AcceptThreadProc(LPVOID)
|
|||||||
if (WaitForSingleObject(g_exit_event, 0) == WAIT_OBJECT_0)
|
if (WaitForSingleObject(g_exit_event, 0) == WAIT_OBJECT_0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
//HANDLE pipe = CreateNamedPipeW(
|
||||||
|
// kPipeName,
|
||||||
|
// PIPE_ACCESS_DUPLEX,
|
||||||
|
// PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
|
||||||
|
// PIPE_UNLIMITED_INSTANCES,
|
||||||
|
// sizeof(Msg),
|
||||||
|
// sizeof(Msg),
|
||||||
|
// 0,
|
||||||
|
// nullptr);
|
||||||
|
|
||||||
|
PSECURITY_DESCRIPTOR security_descriptor = nullptr;
|
||||||
|
|
||||||
|
if (!ConvertStringSecurityDescriptorToSecurityDescriptorW(
|
||||||
|
L"D:P"
|
||||||
|
L"(A;;GA;;;SY)"
|
||||||
|
L"(A;;GA;;;BA)"
|
||||||
|
L"(A;;GRGW;;;AU)"
|
||||||
|
L"S:(ML;;NW;;;ME)",
|
||||||
|
SDDL_REVISION_1,
|
||||||
|
&security_descriptor,
|
||||||
|
nullptr))
|
||||||
|
{
|
||||||
|
Sleep(1000);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
SECURITY_ATTRIBUTES security_attributes{};
|
||||||
|
security_attributes.nLength = sizeof(security_attributes);
|
||||||
|
security_attributes.lpSecurityDescriptor = security_descriptor;
|
||||||
|
security_attributes.bInheritHandle = FALSE;
|
||||||
|
|
||||||
HANDLE pipe = CreateNamedPipeW(
|
HANDLE pipe = CreateNamedPipeW(
|
||||||
kPipeName,
|
kPipeName,
|
||||||
PIPE_ACCESS_DUPLEX,
|
PIPE_ACCESS_DUPLEX,
|
||||||
@@ -485,11 +534,24 @@ static DWORD WINAPI AcceptThreadProc(LPVOID)
|
|||||||
sizeof(Msg),
|
sizeof(Msg),
|
||||||
sizeof(Msg),
|
sizeof(Msg),
|
||||||
0,
|
0,
|
||||||
nullptr);
|
&security_attributes);
|
||||||
|
|
||||||
|
LocalFree(security_descriptor);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (pipe == INVALID_HANDLE_VALUE)
|
if (pipe == INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
//printf("[server] CreateNamedPipeW failed: %lu\n", GetLastError());
|
DWORD error = GetLastError();
|
||||||
|
|
||||||
|
char buffer[128]{};
|
||||||
|
sprintf_s(
|
||||||
|
buffer,
|
||||||
|
"[server] CreateNamedPipeW failed: %lu\n",
|
||||||
|
error);
|
||||||
|
|
||||||
|
OutputDebugStringA(buffer);
|
||||||
|
|
||||||
Sleep(1000);
|
Sleep(1000);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user