From cdbfff87ea3daf6e36d3aa5eb3ceeebfb567e0d4 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Wed, 19 Jan 2022 12:11:48 +0100 Subject: [PATCH] Unified client stop --- client/Mac/mf_client.m | 9 +-------- client/Wayland/wlfreerdp.c | 8 +------- client/Windows/wf_client.c | 14 ++++++-------- client/X11/xf_client.c | 20 +------------------- client/common/client.c | 17 +++++++++++++++++ include/freerdp/client.h | 2 ++ 6 files changed, 28 insertions(+), 42 deletions(-) diff --git a/client/Mac/mf_client.m b/client/Mac/mf_client.m index 43a4dfd97..6326b714d 100644 --- a/client/Mac/mf_client.m +++ b/client/Mac/mf_client.m @@ -67,14 +67,7 @@ static int mfreerdp_client_stop(rdpContext *context) { mfContext *mfc = (mfContext *)context; - freerdp_abort_connect(context->instance); - if (mfc->common.thread) - { - SetEvent(mfc->stopEvent); - WaitForSingleObject(mfc->common.thread, INFINITE); - CloseHandle(mfc->common.thread); - mfc->common.thread = NULL; - } + freerdp_client_common_stop(context); if (mfc->view_ownership) { diff --git a/client/Wayland/wlfreerdp.c b/client/Wayland/wlfreerdp.c index a7c017f95..f6826f593 100644 --- a/client/Wayland/wlfreerdp.c +++ b/client/Wayland/wlfreerdp.c @@ -668,12 +668,6 @@ static int wfl_client_start(rdpContext* context) return 0; } -static int wfl_client_stop(rdpContext* context) -{ - WINPR_UNUSED(context); - return 0; -} - static int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints) { ZeroMemory(pEntryPoints, sizeof(RDP_CLIENT_ENTRY_POINTS)); @@ -685,7 +679,7 @@ static int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints) pEntryPoints->ClientNew = wlf_client_new; pEntryPoints->ClientFree = wlf_client_free; pEntryPoints->ClientStart = wfl_client_start; - pEntryPoints->ClientStop = wfl_client_stop; + pEntryPoints->ClientStop = freerdp_client_common_stop; return 0; } diff --git a/client/Windows/wf_client.c b/client/Windows/wf_client.c index 7be01a66b..4292b94cb 100644 --- a/client/Windows/wf_client.c +++ b/client/Windows/wf_client.c @@ -1412,16 +1412,13 @@ static int wfreerdp_client_start(rdpContext* context) static int wfreerdp_client_stop(rdpContext* context) { + int rc; wfContext* wfc = (wfContext*)context; - if (wfc->common.thread) - { - PostThreadMessage(wfc->mainThreadId, WM_QUIT, 0, 0); - WaitForSingleObject(wfc->common.thread, INFINITE); - CloseHandle(wfc->common.thread); - wfc->common.thread = NULL; - wfc->mainThreadId = 0; - } + WINPR_ASSERT(wfc); + PostThreadMessage(wfc->mainThreadId, WM_QUIT, 0, 0); + rc = freerdp_client_common_stop(context); + wfc->mainThreadId = 0; if (wfc->keyboardThread) { @@ -1435,6 +1432,7 @@ static int wfreerdp_client_stop(rdpContext* context) return 0; } + int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints) { pEntryPoints->Version = 1; diff --git a/client/X11/xf_client.c b/client/X11/xf_client.c index 313cca28e..ebb1dc10d 100644 --- a/client/X11/xf_client.c +++ b/client/X11/xf_client.c @@ -1906,24 +1906,6 @@ static int xfreerdp_client_start(rdpContext* context) return 0; } -static int xfreerdp_client_stop(rdpContext* context) -{ - xfContext* xfc = (xfContext*)context; - - WINPR_ASSERT(xfc); - - freerdp_abort_connect(context->instance); - - if (xfc->common.thread) - { - WaitForSingleObject(xfc->common.thread, INFINITE); - CloseHandle(xfc->common.thread); - xfc->common.thread = NULL; - } - - return 0; -} - static Atom get_supported_atom(xfContext* xfc, const char* atomName) { unsigned long i; @@ -2151,6 +2133,6 @@ int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints) pEntryPoints->ClientNew = xfreerdp_client_new; pEntryPoints->ClientFree = xfreerdp_client_free; pEntryPoints->ClientStart = xfreerdp_client_start; - pEntryPoints->ClientStop = xfreerdp_client_stop; + pEntryPoints->ClientStop = freerdp_client_common_stop; return 0; } diff --git a/client/common/client.c b/client/common/client.c index e9d0c21aa..4460e8ae7 100644 --- a/client/common/client.c +++ b/client/common/client.c @@ -886,3 +886,20 @@ BOOL client_auto_reconnect_ex(freerdp* instance, BOOL (*window_events)(freerdp* WLog_ERR(TAG, "Maximum reconnect retries exceeded"); return FALSE; } + +int freerdp_client_common_stop(rdpContext* context) +{ + rdpClientContext* cctx = (rdpClientContext*)context; + WINPR_ASSERT(cctx); + + freerdp_abort_connect(cctx->context.instance); + + if (cctx->thread) + { + WaitForSingleObject(cctx->thread, INFINITE); + CloseHandle(cctx->thread); + cctx->thread = NULL; + } + + return 0; +} diff --git a/include/freerdp/client.h b/include/freerdp/client.h index 646243cb1..5243e3489 100644 --- a/include/freerdp/client.h +++ b/include/freerdp/client.h @@ -146,6 +146,8 @@ extern "C" FREERDP_API BOOL client_auto_reconnect_ex(freerdp* instance, BOOL (*window_events)(freerdp* instance)); + FREERDP_API int freerdp_client_common_stop(rdpContext* context); + #ifdef __cplusplus } #endif