[client,SDL] fix autoreconnect

retry on handle check failure, not if WaitForMultipleObjects fails
This commit is contained in:
akallabeth 2024-07-18 13:47:27 +02:00
parent 7d6bdbaef8
commit b0320d8068
No known key found for this signature in database
GPG Key ID: A49454A3FC909FD5
5 changed files with 63 additions and 56 deletions

View File

@ -214,8 +214,11 @@ SSIZE_T sdl_retry_dialog(freerdp* instance, const char* what, size_t current, vo
WINPR_ASSERT(what);
auto sdl = get_context(instance->context);
auto settings = instance->context->settings;
const size_t delay = freerdp_settings_get_uint32(settings, FreeRDP_TcpConnectTimeout);
std::lock_guard<CriticalSection> lock(sdl->critical);
WINPR_ASSERT(sdl->connection_dialog);
if (!sdl->connection_dialog)
return delay;
sdl->connection_dialog->setTitle("Retry connection to %s",
freerdp_settings_get_server_name(instance->context->settings));
@ -233,7 +236,6 @@ SSIZE_T sdl_retry_dialog(freerdp* instance, const char* what, size_t current, vo
what);
}
auto settings = instance->context->settings;
const BOOL enabled = freerdp_settings_get_bool(settings, FreeRDP_AutoReconnectionEnabled);
if (!enabled)
@ -244,7 +246,7 @@ SSIZE_T sdl_retry_dialog(freerdp* instance, const char* what, size_t current, vo
}
const size_t max = freerdp_settings_get_uint32(settings, FreeRDP_AutoReconnectMaxRetries);
const size_t delay = freerdp_settings_get_uint32(settings, FreeRDP_TcpConnectTimeout);
if (current >= max)
{
sdl->connection_dialog->showError(

View File

@ -337,7 +337,10 @@ BOOL sdlDispContext::handle_display_event(const SDL_DisplayEvent* ev)
BOOL sdlDispContext::handle_window_event(const SDL_WindowEvent* ev)
{
WINPR_ASSERT(ev);
#if defined(WITH_DEBUG_SDL_EVENTS)
SDL_Log("got windowEvent %s [0x%08" PRIx32 "]", sdl_window_event_str(ev->event).c_str(),
ev->event);
#endif
auto bordered = freerdp_settings_get_bool(_sdl->context()->settings, FreeRDP_Decorations)
? SDL_TRUE
: SDL_FALSE;
@ -351,7 +354,6 @@ BOOL sdlDispContext::handle_window_event(const SDL_WindowEvent* ev)
case SDL_WINDOWEVENT_HIDDEN:
case SDL_WINDOWEVENT_MINIMIZED:
gdi_send_suppress_output(_sdl->context()->gdi, TRUE);
return TRUE;
case SDL_WINDOWEVENT_EXPOSED:

View File

@ -220,6 +220,14 @@ static const struct sdl_exit_code_map_t* sdl_map_entry_by_code(int exit_code)
return nullptr;
}
static void sdl_hide_connection_dialog(SdlContext* sdl)
{
WINPR_ASSERT(sdl);
std::lock_guard<CriticalSection> lock(sdl->critical);
if (sdl->connection_dialog)
sdl->connection_dialog->hide();
}
static const struct sdl_exit_code_map_t* sdl_map_entry_by_error(DWORD error)
{
for (size_t x = 0; x < ARRAYSIZE(sdl_exit_code_map); x++)
@ -914,14 +922,14 @@ static int sdl_run(SdlContext* sdl)
case SDL_WINDOWEVENT:
{
const SDL_WindowEvent* ev = &windowEvent.window;
sdl->disp.handle_window_event(ev);
auto window = sdl->windows.find(ev->windowID);
if (window != sdl->windows.end())
sdl->disp.handle_window_event(ev);
switch (ev->event)
{
case SDL_WINDOWEVENT_RESIZED:
case SDL_WINDOWEVENT_SIZE_CHANGED:
{
auto window = sdl->windows.find(ev->windowID);
if (window != sdl->windows.end())
{
window->second.fill();
@ -931,7 +939,6 @@ static int sdl_run(SdlContext* sdl)
break;
case SDL_WINDOWEVENT_MOVED:
{
auto window = sdl->windows.find(ev->windowID);
if (window != sdl->windows.end())
{
auto r = window->second.rect();
@ -1071,11 +1078,7 @@ static BOOL sdl_post_connect(freerdp* instance)
auto sdl = get_context(context);
// Retry was successful, discard dialog
{
std::lock_guard<CriticalSection> lock(sdl->critical);
if (sdl->connection_dialog)
sdl->connection_dialog->hide();
}
sdl_hide_connection_dialog(sdl);
if (freerdp_settings_get_bool(context->settings, FreeRDP_AuthenticationOnly))
{
@ -1233,12 +1236,19 @@ static DWORD WINAPI sdl_client_thread_proc(SdlContext* sdl)
break;
}
status = WaitForMultipleObjects(nCount, handles, FALSE, 100);
status = WaitForMultipleObjects(nCount, handles, FALSE, INFINITE);
if (status == WAIT_FAILED)
break;
if (!freerdp_check_event_handles(context))
{
if (client_auto_reconnect(instance))
{
// Retry was successful, discard dialog
sdl_hide_connection_dialog(sdl);
continue;
}
else
{
/*
@ -1252,14 +1262,8 @@ static DWORD WINAPI sdl_client_thread_proc(SdlContext* sdl)
if (freerdp_get_last_error(context) == FREERDP_ERROR_SUCCESS)
WLog_Print(sdl->log, WLOG_ERROR, "WaitForMultipleObjects failed with %" PRIu32 "",
status);
break;
}
if (!freerdp_check_event_handles(context))
{
if (freerdp_get_last_error(context) == FREERDP_ERROR_SUCCESS)
WLog_Print(sdl->log, WLOG_ERROR, "Failed to check FreeRDP event handles");
break;
}
}

View File

@ -214,8 +214,12 @@ SSIZE_T sdl_retry_dialog(freerdp* instance, const char* what, size_t current, vo
WINPR_ASSERT(what);
auto sdl = get_context(instance->context);
auto settings = instance->context->settings;
const BOOL enabled = freerdp_settings_get_bool(settings, FreeRDP_AutoReconnectionEnabled);
const size_t delay = freerdp_settings_get_uint32(settings, FreeRDP_TcpConnectTimeout);
std::lock_guard<CriticalSection> lock(sdl->critical);
WINPR_ASSERT(sdl->connection_dialog);
if (!sdl->connection_dialog)
return delay;
sdl->connection_dialog->setTitle("Retry connection to %s",
freerdp_settings_get_server_name(instance->context->settings));
@ -233,9 +237,6 @@ SSIZE_T sdl_retry_dialog(freerdp* instance, const char* what, size_t current, vo
what);
}
auto settings = instance->context->settings;
const BOOL enabled = freerdp_settings_get_bool(settings, FreeRDP_AutoReconnectionEnabled);
if (!enabled)
{
sdl->connection_dialog->showError(
@ -244,7 +245,6 @@ SSIZE_T sdl_retry_dialog(freerdp* instance, const char* what, size_t current, vo
}
const size_t max = freerdp_settings_get_uint32(settings, FreeRDP_AutoReconnectMaxRetries);
const size_t delay = freerdp_settings_get_uint32(settings, FreeRDP_TcpConnectTimeout);
if (current >= max)
{
sdl->connection_dialog->showError(

View File

@ -220,6 +220,14 @@ static const struct sdl_exit_code_map_t* sdl_map_entry_by_code(int exit_code)
return nullptr;
}
static void sdl_hide_connection_dialog(SdlContext* sdl)
{
WINPR_ASSERT(sdl);
std::lock_guard<CriticalSection> lock(sdl->critical);
if (sdl->connection_dialog)
sdl->connection_dialog->hide();
}
static const struct sdl_exit_code_map_t* sdl_map_entry_by_error(DWORD error)
{
for (size_t x = 0; x < ARRAYSIZE(sdl_exit_code_map); x++)
@ -1007,35 +1015,29 @@ static int sdl_run(SdlContext* sdl)
(windowEvent.type <= SDL_EVENT_WINDOW_LAST))
{
const SDL_WindowEvent* ev = &windowEvent.window;
sdl->disp.handle_window_event(ev);
switch (ev->type)
auto window = sdl->windows.find(ev->windowID);
if (window != sdl->windows.end())
{
case SDL_EVENT_WINDOW_RESIZED:
case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
sdl->disp.handle_window_event(ev);
switch (ev->type)
{
auto window = sdl->windows.find(ev->windowID);
if (window != sdl->windows.end())
{
case SDL_EVENT_WINDOW_RESIZED:
case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
window->second.fill();
window->second.updateSurface();
}
}
break;
break;
case SDL_EVENT_WINDOW_MOVED:
{
auto window = sdl->windows.find(ev->windowID);
if (window != sdl->windows.end())
{
auto r = window->second.rect();
auto id = window->second.id();
WLog_DBG(SDL_TAG, "%lu: %dx%d-%dx%d", id, r.x, r.y, r.w, r.h);
}
auto r = window->second.rect();
auto id = window->second.id();
WLog_DBG(SDL_TAG, "%lu: %dx%d-%dx%d", id, r.x, r.y, r.w, r.h);
}
break;
default:
break;
}
}
}
break;
}
@ -1066,11 +1068,7 @@ static BOOL sdl_post_connect(freerdp* instance)
auto sdl = get_context(context);
// Retry was successful, discard dialog
{
std::lock_guard<CriticalSection> lock(sdl->critical);
if (sdl->connection_dialog)
sdl->connection_dialog->hide();
}
sdl_hide_connection_dialog(sdl);
if (freerdp_settings_get_bool(context->settings, FreeRDP_AuthenticationOnly))
{
@ -1228,12 +1226,19 @@ static DWORD WINAPI sdl_client_thread_proc(SdlContext* sdl)
break;
}
status = WaitForMultipleObjects(nCount, handles, FALSE, 100);
status = WaitForMultipleObjects(nCount, handles, FALSE, INFINITE);
if (status == WAIT_FAILED)
break;
if (!freerdp_check_event_handles(context))
{
if (client_auto_reconnect(instance))
{
// Retry was successful, discard dialog
sdl_hide_connection_dialog(sdl);
continue;
}
else
{
/*
@ -1247,14 +1252,8 @@ static DWORD WINAPI sdl_client_thread_proc(SdlContext* sdl)
if (freerdp_get_last_error(context) == FREERDP_ERROR_SUCCESS)
WLog_Print(sdl->log, WLOG_ERROR, "WaitForMultipleObjects failed with %" PRIu32 "",
status);
break;
}
if (!freerdp_check_event_handles(context))
{
if (freerdp_get_last_error(context) == FREERDP_ERROR_SUCCESS)
WLog_Print(sdl->log, WLOG_ERROR, "Failed to check FreeRDP event handles");
break;
}
}