GUACAMOLE-203: Tighten up code, implement constant for socket poll timer.

This commit is contained in:
Nick Couchman 2017-05-31 19:33:47 -04:00 committed by Nick Couchman
parent 75019f5e4b
commit f693b02e12
2 changed files with 15 additions and 16 deletions

View File

@ -53,6 +53,11 @@
*/ */
#define GUAC_SSH_DEFAULT_RECORDING_NAME "recording" #define GUAC_SSH_DEFAULT_RECORDING_NAME "recording"
/**
* The default polling timer for SSH activity in milliseconds.
*/
#define GUAC_SSH_DEFAULT_POLL_TIMER 1000
/** /**
* Settings for the SSH connection. The values for this structure are parsed * Settings for the SSH connection. The values for this structure are parsed
* from the arguments given during the Guacamole protocol handshake using the * from the arguments given during the Guacamole protocol handshake using the

View File

@ -225,9 +225,8 @@ void* ssh_client_thread(void* data) {
} }
/* Set keepalive configuration for session */ /* Set keepalive configuration for session */
if (settings->server_alive_interval > 0) { if (settings->server_alive_interval > 1)
libssh2_keepalive_config(ssh_client->session->session, 1, settings->server_alive_interval); libssh2_keepalive_config(ssh_client->session->session, 1, settings->server_alive_interval);
}
pthread_mutex_init(&ssh_client->term_channel_lock, NULL); pthread_mutex_init(&ssh_client->term_channel_lock, NULL);
@ -323,17 +322,13 @@ void* ssh_client_thread(void* data) {
/* While data available, write to terminal */ /* While data available, write to terminal */
int bytes_read = 0; int bytes_read = 0;
int timeout = 0;
for (;;) { for (;;) {
/* Track total amount of data read */ /* Track total amount of data read */
int total_read = 0; int total_read = 0;
/* Set up return value for keepalives */ /* Timer for polling socket activity */
int alive = 0; int timer;
/* Timer for keepalives */
int sleep = 0;
pthread_mutex_lock(&(ssh_client->term_channel_lock)); pthread_mutex_lock(&(ssh_client->term_channel_lock));
@ -344,16 +339,15 @@ void* ssh_client_thread(void* data) {
} }
/* Send keepalive at configured interval */ /* Send keepalive at configured interval */
if (settings->server_alive_interval > 0) { if (settings->server_alive_interval > 1) {
alive = libssh2_keepalive_send(ssh_client->session->session, &timeout); int timeout = 0;
/* Sending the keepalive failed, so we break out */ if(libssh2_keepalive_send(ssh_client->session->session, &timeout) > 0)
if (alive > 0)
break; break;
sleep = timeout * 1000; timer = timeout * 1000;
} }
/* If keepalive is not configured, sleep for the default of 1 second */ /* If keepalive is not configured, sleep for the default of 1 second */
else else
sleep = 1000; timer = GUAC_SSH_DEFAULT_POLL_TIMER;
/* Read terminal data */ /* Read terminal data */
bytes_read = libssh2_channel_read(ssh_client->term_channel, bytes_read = libssh2_channel_read(ssh_client->term_channel,
@ -394,8 +388,8 @@ void* ssh_client_thread(void* data) {
.revents = 0, .revents = 0,
}}; }};
/* Wait up to computed sleep time */ /* Wait up to computed timer */
if (poll(fds, 1, sleep) < 0) if (poll(fds, 1, timer) < 0)
break; break;
} }