From 520dd5ede336c37bfb45224d46cd7e4d46813ac1 Mon Sep 17 00:00:00 2001 From: Virtually Nick Date: Thu, 16 Feb 2023 17:48:20 -0500 Subject: [PATCH] GUACAMOLE-600: Add support for setting the VNC connection timeout. --- src/protocols/vnc/settings.c | 10 ++++++++++ src/protocols/vnc/settings.h | 10 ++++++++++ src/protocols/vnc/vnc.c | 3 ++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/protocols/vnc/settings.c b/src/protocols/vnc/settings.c index a476b2c1..49b4ba50 100644 --- a/src/protocols/vnc/settings.c +++ b/src/protocols/vnc/settings.c @@ -36,6 +36,7 @@ const char* GUAC_VNC_CLIENT_ARGS[] = { "hostname", "port", + "timeout", "read-only", "encodings", GUAC_VNC_ARGV_USERNAME, @@ -108,6 +109,11 @@ enum VNC_ARGS_IDX { */ IDX_PORT, + /** + * The number of seconds to wait for the connection before timing out. + */ + IDX_TIMEOUT, + /** * "true" if this connection should be read-only (user input should be * dropped), "false" or blank otherwise. @@ -405,6 +411,10 @@ guac_vnc_settings* guac_vnc_parse_args(guac_user* user, guac_user_parse_args_int(user, GUAC_VNC_CLIENT_ARGS, argv, IDX_PORT, 0); + settings->timeout = + guac_user_parse_args_int(user, GUAC_VNC_CLIENT_ARGS, argv, + IDX_TIMEOUT, GUAC_VNC_DEFAULT_CONNECTION_TIMEOUT); + settings->username = guac_user_parse_args_string(user, GUAC_VNC_CLIENT_ARGS, argv, IDX_USERNAME, NULL); diff --git a/src/protocols/vnc/settings.h b/src/protocols/vnc/settings.h index 76139bd4..aa2b175b 100644 --- a/src/protocols/vnc/settings.h +++ b/src/protocols/vnc/settings.h @@ -25,6 +25,11 @@ #include +/** + * The default number of seconds to wait for a connection before timing out. + */ +#define GUAC_VNC_DEFAULT_CONNECTION_TIMEOUT 10 + /** * The filename to use for the screen recording, if not specified. */ @@ -45,6 +50,11 @@ typedef struct guac_vnc_settings { */ int port; + /** + * The number of seconds to wait for the connection before timing out. + */ + int timeout; + /** * The username given in the arguments. */ diff --git a/src/protocols/vnc/vnc.c b/src/protocols/vnc/vnc.c index 3b94d5e7..ad6761ef 100644 --- a/src/protocols/vnc/vnc.c +++ b/src/protocols/vnc/vnc.c @@ -201,9 +201,10 @@ rfbClient* guac_vnc_get_client(guac_client* client) { rfb_client->MallocFrameBuffer = guac_vnc_malloc_framebuffer; rfb_client->canHandleNewFBSize = 1; - /* Set hostname and port */ + /* Set hostname, port, and timeout */ rfb_client->serverHost = strdup(vnc_settings->hostname); rfb_client->serverPort = vnc_settings->port; + rfb_client->connectTimeout = vnc_settings->timeout; #ifdef ENABLE_VNC_REPEATER /* Set repeater parameters if specified */