From e40c5ce2ceec4c91a7d2156714b9b5c1cdef274a Mon Sep 17 00:00:00 2001 From: Zhang Zhaolong Date: Sun, 27 Apr 2014 20:32:52 +0800 Subject: [PATCH 1/2] libfreerdp-core: fix assignment after memory free. --- libfreerdp/core/connection.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/libfreerdp/core/connection.c b/libfreerdp/core/connection.c index 14be79289..f11404692 100644 --- a/libfreerdp/core/connection.c +++ b/libfreerdp/core/connection.c @@ -371,8 +371,6 @@ BOOL rdp_client_redirect(rdpRdp* rdp) BOOL rdp_client_reconnect(rdpRdp* rdp) { - UINT32 i; - transport_disconnect(rdp->transport); mcs_free(rdp->mcs); @@ -380,12 +378,6 @@ BOOL rdp_client_reconnect(rdpRdp* rdp) license_free(rdp->license); transport_free(rdp->transport); - /* Reset virtual channel status */ - for (i = 0; i < rdp->mcs->channelCount; i++) - { - rdp->mcs->channels[i].joined = FALSE; - } - rdp->transport = transport_new(rdp->settings); rdp->license = license_new(rdp); rdp->nego = nego_new(rdp->transport); From 92c77d01348506b9c6b073f2ca8223c5e33eee14 Mon Sep 17 00:00:00 2001 From: Zhang Zhaolong Date: Sun, 27 Apr 2014 20:52:45 +0800 Subject: [PATCH 2/2] wfreerdp: port auto reconnection to Windows. --- client/Windows/wf_interface.c | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/client/Windows/wf_interface.c b/client/Windows/wf_interface.c index cbb9ddbf1..2e5c19be9 100644 --- a/client/Windows/wf_interface.c +++ b/client/Windows/wf_interface.c @@ -578,6 +578,47 @@ BOOL wf_check_fds(freerdp* instance) return TRUE; } +static BOOL wf_auto_reconnect(freerdp* instance) +{ + wfContext* wfc = (wfContext *)instance->context; + + UINT32 num_retries = 0; + UINT32 max_retries = instance->settings->AutoReconnectMaxRetries; + + /* Only auto reconnect on network disconnects. */ + if (freerdp_error_info(instance) != 0) + return FALSE; + + /* A network disconnect was detected */ + fprintf(stderr, "Network disconnect!\n"); + if (!instance->settings->AutoReconnectionEnabled) + { + /* No auto-reconnect - just quit */ + return FALSE; + } + + /* Perform an auto-reconnect. */ + for (;;) + { + /* Quit retrying if max retries has been exceeded */ + if (num_retries++ >= max_retries) + return FALSE; + + /* Attempt the next reconnect */ + fprintf(stderr, "Attempting reconnect (%u of %u)\n", num_retries, max_retries); + if (freerdp_reconnect(instance)) + { + return TRUE; + } + + Sleep(5000); + } + + fprintf(stderr, "Maximum reconnect retries exceeded\n"); + + return FALSE; +} + DWORD WINAPI wf_client_thread(LPVOID lpParam) { MSG msg; @@ -658,6 +699,9 @@ DWORD WINAPI wf_client_thread(LPVOID lpParam) if (freerdp_check_fds(instance) != TRUE) { + if (wf_auto_reconnect(instance)) + continue; + fprintf(stderr, "Failed to check FreeRDP file descriptor\n"); break; }