GUACAMOLE-1687: Clean, document, and clarify usage of tunnel timer reset function.

This commit is contained in:
Michael Jumper
2022-09-28 10:50:25 -07:00
parent 3036c96a1f
commit 7f2ea222bb

View File

@@ -356,12 +356,16 @@ Guacamole.HTTPTunnel = function(tunnelURL, crossDomain, extraTunnelHeaders) {
} }
/** /**
* Initiates a timeout which, if data is not received, causes the tunnel * Resets the state of timers tracking network activity and stability. If
* to close with an error. * those timers are not yet started, invoking this function starts them.
* * This function should be invoked when the tunnel is established and every
* time there is network activity on the tunnel, such that the timers can
* safely assume the network and/or server are not responding if this
* function has not been invoked for a significant period of time.
*
* @private * @private
*/ */
function reset_timeout() { var resetTimers = function resetTimers() {
// Get rid of old timeouts (if any) // Get rid of old timeouts (if any)
window.clearTimeout(receive_timeout); window.clearTimeout(receive_timeout);
@@ -381,7 +385,7 @@ Guacamole.HTTPTunnel = function(tunnelURL, crossDomain, extraTunnelHeaders) {
tunnel.setState(Guacamole.Tunnel.State.UNSTABLE); tunnel.setState(Guacamole.Tunnel.State.UNSTABLE);
}, tunnel.unstableThreshold); }, tunnel.unstableThreshold);
} };
/** /**
* Closes this tunnel, signaling the given status and corresponding * Closes this tunnel, signaling the given status and corresponding
@@ -491,7 +495,7 @@ Guacamole.HTTPTunnel = function(tunnelURL, crossDomain, extraTunnelHeaders) {
message_xmlhttprequest.onreadystatechange = function() { message_xmlhttprequest.onreadystatechange = function() {
if (message_xmlhttprequest.readyState === 4) { if (message_xmlhttprequest.readyState === 4) {
reset_timeout(); resetTimers();
// If an error occurs during send, handle it // If an error occurs during send, handle it
if (message_xmlhttprequest.status !== 200) if (message_xmlhttprequest.status !== 200)
@@ -581,7 +585,7 @@ Guacamole.HTTPTunnel = function(tunnelURL, crossDomain, extraTunnelHeaders) {
if (xmlhttprequest.readyState === 3 || if (xmlhttprequest.readyState === 3 ||
xmlhttprequest.readyState === 4) { xmlhttprequest.readyState === 4) {
reset_timeout(); resetTimers();
// Also poll every 30ms (some browsers don't repeatedly call onreadystatechange for new data) // Also poll every 30ms (some browsers don't repeatedly call onreadystatechange for new data)
if (pollingMode === POLLING_ENABLED) { if (pollingMode === POLLING_ENABLED) {
@@ -742,7 +746,7 @@ Guacamole.HTTPTunnel = function(tunnelURL, crossDomain, extraTunnelHeaders) {
this.connect = function(data) { this.connect = function(data) {
// Start waiting for connect // Start waiting for connect
reset_timeout(); resetTimers();
// Mark the tunnel as connecting // Mark the tunnel as connecting
tunnel.setState(Guacamole.Tunnel.State.CONNECTING); tunnel.setState(Guacamole.Tunnel.State.CONNECTING);
@@ -760,7 +764,7 @@ Guacamole.HTTPTunnel = function(tunnelURL, crossDomain, extraTunnelHeaders) {
return; return;
} }
reset_timeout(); resetTimers();
// Get UUID and HTTP-specific tunnel session token from response // Get UUID and HTTP-specific tunnel session token from response
tunnel.setUUID(connect_xmlhttprequest.responseText); tunnel.setUUID(connect_xmlhttprequest.responseText);
@@ -932,12 +936,16 @@ Guacamole.WebSocketTunnel = function(tunnelURL) {
}; };
/** /**
* Initiates a timeout which, if data is not received, causes the tunnel * Resets the state of timers tracking network activity and stability. If
* to close with an error. * those timers are not yet started, invoking this function starts them.
* * This function should be invoked when the tunnel is established and every
* time there is network activity on the tunnel, such that the timers can
* safely assume the network and/or server are not responding if this
* function has not been invoked for a significant period of time.
*
* @private * @private
*/ */
function reset_timeout() { var resetTimers = function resetTimers() {
// Get rid of old timeouts (if any) // Get rid of old timeouts (if any)
window.clearTimeout(receive_timeout); window.clearTimeout(receive_timeout);
@@ -968,7 +976,7 @@ Guacamole.WebSocketTunnel = function(tunnelURL) {
else else
sendPing(); sendPing();
} };
/** /**
* Closes this tunnel, signaling the given status and corresponding * Closes this tunnel, signaling the given status and corresponding
@@ -1043,7 +1051,7 @@ Guacamole.WebSocketTunnel = function(tunnelURL) {
this.connect = function(data) { this.connect = function(data) {
reset_timeout(); resetTimers();
// Mark the tunnel as connecting // Mark the tunnel as connecting
tunnel.setState(Guacamole.Tunnel.State.CONNECTING); tunnel.setState(Guacamole.Tunnel.State.CONNECTING);
@@ -1052,7 +1060,7 @@ Guacamole.WebSocketTunnel = function(tunnelURL) {
socket = new WebSocket(tunnelURL + "?" + data, "guacamole"); socket = new WebSocket(tunnelURL + "?" + data, "guacamole");
socket.onopen = function(event) { socket.onopen = function(event) {
reset_timeout(); resetTimers();
}; };
socket.onclose = function(event) { socket.onclose = function(event) {
@@ -1074,7 +1082,7 @@ Guacamole.WebSocketTunnel = function(tunnelURL) {
socket.onmessage = function(event) { socket.onmessage = function(event) {
reset_timeout(); resetTimers();
var message = event.data; var message = event.data;
var startIndex = 0; var startIndex = 0;