xfreerdp: disable auto-reconnect by default, add command-line option
authorMarc-André Moreau <marcandre.moreau@gmail.com>
Thu, 27 Feb 2014 21:55:07 +0000 (16:55 -0500)
committerMarc-André Moreau <marcandre.moreau@gmail.com>
Thu, 27 Feb 2014 21:55:07 +0000 (16:55 -0500)
client/X11/xf_client.c
client/common/cmdline.c
libfreerdp/core/settings.c

index 331cae1..a47b0e6 100644 (file)
@@ -51,8 +51,6 @@
 #include <X11/extensions/Xrender.h>
 #endif
 
-#define WITH_AUTORECONNECT
-
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -1367,19 +1365,20 @@ void* xf_channels_thread(void* arg)
        return NULL;
 }
 
-#ifdef WITH_AUTORECONNECT
 BOOL xf_auto_reconnect(freerdp* instance)
 {
-       xfContext* xfc = (xfContext*)instance->context;
+       xfContext* xfc = (xfContext*) 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;
+       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 */
@@ -1397,6 +1396,7 @@ BOOL xf_auto_reconnect(freerdp* instance)
 
                /* Attempt the next reconnect */
                fprintf(stderr, "Attempting reconnect (%u of %u)\n", num_retries, max_retries);
+
                if (freerdp_reconnect(instance))
                {
                        xfc->disconnect = FALSE;
@@ -1410,7 +1410,6 @@ BOOL xf_auto_reconnect(freerdp* instance)
 
        return FALSE;
 }
-#endif
 
 /** Main loop for the rdp connection.
  *  It will be run from the thread's entry point (thread_func()).
@@ -1458,11 +1457,6 @@ void* xf_thread(void* param)
        ZeroMemory(wfds, sizeof(wfds));
        ZeroMemory(&timeout, sizeof(struct timeval));
 
-#ifdef WITH_AUTORECONNECT
-       instance->settings->AutoReconnectionEnabled = TRUE;
-       instance->settings->AutoReconnectMaxRetries = 20;
-#endif
-
        status = freerdp_connect(instance);
 
        xfc = (xfContext*) instance->context;
@@ -1607,9 +1601,9 @@ void* xf_thread(void* param)
                {
                        if (freerdp_check_fds(instance) != TRUE)
                        {
-#ifdef WITH_AUTORECONNECT
-                               if (xf_auto_reconnect(instance)) continue;
-#endif
+                               if (xf_auto_reconnect(instance))
+                                       continue;
+
                                fprintf(stderr, "Failed to check FreeRDP file descriptor\n");
                                break;
                        }
index 29d964f..a894a94 100644 (file)
@@ -148,6 +148,7 @@ COMMAND_LINE_ARGUMENT_A args[] =
        { "help", COMMAND_LINE_VALUE_FLAG | COMMAND_LINE_PRINT_HELP, NULL, NULL, NULL, -1, "?", "print help" },
        { "play-rfx", COMMAND_LINE_VALUE_REQUIRED, "<pcap file>", NULL, NULL, -1, NULL, "Replay rfx pcap file" },
        { "auth-only", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "Authenticate only." },
+       { "auto-reconnect", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "Automatic reconnection" },
        { "reconnect-cookie", COMMAND_LINE_VALUE_REQUIRED, "<base64 cookie>", NULL, NULL, -1, NULL, "Pass base64 reconnect cookie to the connection" },
        { "print-reconnect-cookie", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "Print base64 reconnect cookie after connecting" },
        { "heartbeat", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "Support heartbeat PDUs" },
@@ -1716,6 +1717,10 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
                {
                        settings->AuthenticationOnly = arg->Value ? TRUE : FALSE;
                }
+               CommandLineSwitchCase(arg, "auto-reconnect")
+               {
+                       settings->AutoReconnectionEnabled = arg->Value ? TRUE : FALSE;
+               }
                CommandLineSwitchCase(arg, "reconnect-cookie")
                {
                        BYTE *base64;
index 5db64ac..5b9f992 100644 (file)
@@ -387,7 +387,7 @@ rdpSettings* freerdp_settings_new(DWORD flags)
                settings->FrameAcknowledge = 2;
                settings->MouseMotion = TRUE;
 
-               settings->AutoReconnectionEnabled = TRUE;
+               settings->AutoReconnectionEnabled = FALSE;
                settings->AutoReconnectMaxRetries = 20;
 
                settings->ClientAutoReconnectCookie = (ARC_CS_PRIVATE_PACKET*) malloc(sizeof(ARC_CS_PRIVATE_PACKET));