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; } 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);