GUACAMOLE-203: Implement keepalive config in SSH connection.

This commit is contained in:
Nick Couchman 2017-05-31 08:00:09 -04:00 committed by Nick Couchman
parent f42f05aab7
commit 8ab7e56972

View File

@ -224,6 +224,11 @@ void* ssh_client_thread(void* data) {
return NULL; return NULL;
} }
/* Set keepalive configuration for session */
if (settings->server_alive_interval > 0) {
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);
/* Open channel for terminal */ /* Open channel for terminal */
@ -318,11 +323,18 @@ 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 */
int alive = 0;
/* Timer for keepalives */
int sleep = 0;
pthread_mutex_lock(&(ssh_client->term_channel_lock)); pthread_mutex_lock(&(ssh_client->term_channel_lock));
/* Stop reading at EOF */ /* Stop reading at EOF */
@ -331,6 +343,16 @@ void* ssh_client_thread(void* data) {
break; break;
} }
/* Send keepalive at configured interval */
if (settings->server_alive_interval > 0) {
alive = libssh2_keepalive_send(ssh_client->session->session, &timeout);
if (alive > 0)
break;
sleep = timeout * 1000;
}
else
sleep = 1000;
/* Read terminal data */ /* Read terminal data */
bytes_read = libssh2_channel_read(ssh_client->term_channel, bytes_read = libssh2_channel_read(ssh_client->term_channel,
buffer, sizeof(buffer)); buffer, sizeof(buffer));
@ -370,8 +392,8 @@ void* ssh_client_thread(void* data) {
.revents = 0, .revents = 0,
}}; }};
/* Wait up to one second */ /* Wait up to computed sleep time */
if (poll(fds, 1, 1000) < 0) if (poll(fds, 1, sleep) < 0)
break; break;
} }