GUACAMOLE-600: Add support for setting the Telnet connection timeout.
This commit is contained in:
parent
47b9360d46
commit
0c0fe2e7a4
@ -37,6 +37,7 @@
|
|||||||
const char* GUAC_TELNET_CLIENT_ARGS[] = {
|
const char* GUAC_TELNET_CLIENT_ARGS[] = {
|
||||||
"hostname",
|
"hostname",
|
||||||
"port",
|
"port",
|
||||||
|
"timeout",
|
||||||
"username",
|
"username",
|
||||||
"username-regex",
|
"username-regex",
|
||||||
"password",
|
"password",
|
||||||
@ -81,6 +82,11 @@ enum TELNET_ARGS_IDX {
|
|||||||
*/
|
*/
|
||||||
IDX_PORT,
|
IDX_PORT,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of seconds to wait for the remote server to respond. Optional.
|
||||||
|
*/
|
||||||
|
IDX_TIMEOUT,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the user to login as. Optional.
|
* The name of the user to login as. Optional.
|
||||||
*/
|
*/
|
||||||
@ -429,6 +435,11 @@ guac_telnet_settings* guac_telnet_parse_args(guac_user* user,
|
|||||||
guac_user_parse_args_string(user, GUAC_TELNET_CLIENT_ARGS, argv,
|
guac_user_parse_args_string(user, GUAC_TELNET_CLIENT_ARGS, argv,
|
||||||
IDX_PORT, GUAC_TELNET_DEFAULT_PORT);
|
IDX_PORT, GUAC_TELNET_DEFAULT_PORT);
|
||||||
|
|
||||||
|
/* Read connection timeout */
|
||||||
|
settings->timeout =
|
||||||
|
guac_user_parse_args_int(user, GUAC_TELNET_CLIENT_ARGS, argv,
|
||||||
|
IDX_TIMEOUT, GUAC_TELNET_DEFAULT_TIMEOUT);
|
||||||
|
|
||||||
/* Read typescript path */
|
/* Read typescript path */
|
||||||
settings->typescript_path =
|
settings->typescript_path =
|
||||||
guac_user_parse_args_string(user, GUAC_TELNET_CLIENT_ARGS, argv,
|
guac_user_parse_args_string(user, GUAC_TELNET_CLIENT_ARGS, argv,
|
||||||
|
@ -33,6 +33,12 @@
|
|||||||
*/
|
*/
|
||||||
#define GUAC_TELNET_DEFAULT_PORT "23"
|
#define GUAC_TELNET_DEFAULT_PORT "23"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The default number of seconds to wait for a successful connection before
|
||||||
|
* timing out.
|
||||||
|
*/
|
||||||
|
#define GUAC_TELNET_DEFAULT_TIMEOUT 10
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The filename to use for the typescript, if not specified.
|
* The filename to use for the typescript, if not specified.
|
||||||
*/
|
*/
|
||||||
@ -72,6 +78,11 @@ typedef struct guac_telnet_settings {
|
|||||||
*/
|
*/
|
||||||
char* port;
|
char* port;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of seconds to wait for a connection before timing out.
|
||||||
|
*/
|
||||||
|
int timeout;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the user to login as, if any. If no username is specified,
|
* The name of the user to login as, if any. If no username is specified,
|
||||||
* this will be NULL.
|
* this will be NULL.
|
||||||
|
@ -424,9 +424,25 @@ static telnet_t* __guac_telnet_create_session(guac_client* client) {
|
|||||||
NI_NUMERICHOST | NI_NUMERICSERV)))
|
NI_NUMERICHOST | NI_NUMERICSERV)))
|
||||||
guac_client_log(client, GUAC_LOG_DEBUG, "Unable to resolve host: %s", gai_strerror(retval));
|
guac_client_log(client, GUAC_LOG_DEBUG, "Unable to resolve host: %s", gai_strerror(retval));
|
||||||
|
|
||||||
/* Connect */
|
fd_set fdset;
|
||||||
if (connect(fd, current_address->ai_addr,
|
FD_ZERO(&fdset);
|
||||||
current_address->ai_addrlen) == 0) {
|
FD_SET(fd, &fdset);
|
||||||
|
|
||||||
|
struct timeval timeout_tv;
|
||||||
|
timeout_tv.tv_sec = settings->timeout;
|
||||||
|
timeout_tv.tv_usec = 0;
|
||||||
|
|
||||||
|
connect(fd, current_address->ai_addr, current_address->ai_addrlen);
|
||||||
|
|
||||||
|
retval = select(fd + 1, NULL, &fdset, NULL, &timeout_tv);
|
||||||
|
|
||||||
|
if (retval == 0) {
|
||||||
|
guac_client_log(client, GUAC_LOG_ERROR, "Timeout connecting to "
|
||||||
|
"host %s, port %s", connected_address, connected_port);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (retval > 0) {
|
||||||
|
|
||||||
guac_client_log(client, GUAC_LOG_DEBUG, "Successfully connected to "
|
guac_client_log(client, GUAC_LOG_DEBUG, "Successfully connected to "
|
||||||
"host %s, port %s", connected_address, connected_port);
|
"host %s, port %s", connected_address, connected_port);
|
||||||
|
Loading…
Reference in New Issue
Block a user