From fa3794007535201210b624f2fc93706f4ba252b5 Mon Sep 17 00:00:00 2001 From: logicog Date: Fri, 6 Mar 2026 12:06:13 +0100 Subject: [PATCH] Control xhttp concurrency --- html/bandwidth.js | 12 +++++++----- html/eee.js | 12 +++++++----- html/index.html | 7 +++++++ html/l2.js | 8 ++++++-- html/lag.js | 13 ++++++++----- html/main.js | 42 ++++++++++++++++++++++++++++++++++++------ html/mirror.js | 15 +++++++++------ html/ports.js | 15 ++++++++------- html/stat.js | 13 ++++++++++--- html/vlan.js | 14 ++++++++------ 10 files changed, 106 insertions(+), 45 deletions(-) diff --git a/html/bandwidth.js b/html/bandwidth.js index a29cc01..6b7f203 100644 --- a/html/bandwidth.js +++ b/html/bandwidth.js @@ -3,7 +3,6 @@ function createBW() { var tbl = document.getElementById('bwtable'); const limit = '' if (tbl.rows.length <= 2 && numPorts) { - clearInterval(createBWInterval); console.log("CREATING TABLE ", tbl.rows.length); for (let i = 2; i < 2 + numPorts; i++) { const tr = tbl.insertRow(); @@ -94,6 +93,7 @@ async function applyBandwidth(i) { function getBW() { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { + console.log("IN getBW "); if (this.readyState == 4 && this.status == 200) { const s = JSON.parse(xhttp.responseText); console.log("BW: ", JSON.stringify(s)); @@ -126,11 +126,13 @@ function getBW() { } }; xhttp.open("GET", "/bandwidth.json", true); - xhttp.timeout = 1500; xhttp.send(); + xhttp.timeout = 1500; sendXHTTP(xhttp); } window.addEventListener("load", function() { - getBW(); - const iCount = setInterval(getBW, 2000); + update( () => { + createBW(); + getBW(); + const interval = setInterval(update, 2000); + }); }); -const createBWInterval = setInterval(createBW, 1010); diff --git a/html/eee.js b/html/eee.js index c5140eb..af423ea 100644 --- a/html/eee.js +++ b/html/eee.js @@ -1,7 +1,6 @@ function createEEE() { var tbl = document.getElementById('eeetable'); if (tbl.rows.length <= 2 && numPorts) { - clearInterval(createEEEInterval); console.log("CREATING TABLE ", tbl.rows.length); for (let i = 2; i < 2 + numPorts; i++) { console.log("Table row: " + i + "pState: " + pState[i-2]); @@ -40,11 +39,14 @@ function getEEE() { } }; xhttp.open("GET", "/eee.json", true); - xhttp.timeout = 1500; xhttp.send(); + xhttp.timeout = 1500; sendXHTTP(xhttp); } window.addEventListener("load", function() { - getEEE(); - const iCount = setInterval(getEEE, 2000); + update( () => { + createEEE(); + getEEE(); + const interval = setInterval(update, 2000); + const iCount = setInterval(getEEE, 2000); + }); }); -const createEEEInterval = setInterval(createEEE, 1000); diff --git a/html/index.html b/html/index.html index 04532db..c9d1b31 100644 --- a/html/index.html +++ b/html/index.html @@ -2,6 +2,13 @@ + FreeSwitchOS Main Page diff --git a/html/l2.js b/html/l2.js index b5af281..c39dd27 100644 --- a/html/l2.js +++ b/html/l2.js @@ -130,10 +130,14 @@ function getL2() { } }; xhttp.open("GET", "/l2.json?idx=" + l2CurrentEntry, true); - xhttp.timeout = 1500; xhttp.send(); + xhttp.timeout = 1500; sendXHTTP(xhttp); } window.addEventListener("load", function() { - l2GetInterval = setInterval(getL2, 1000); + update( () => { + getL2(); + const interval = setInterval(update, 2000); + l2GetInterval = setInterval(getL2, 1000); + });; }); diff --git a/html/lag.js b/html/lag.js index 4006880..2c56d1a 100644 --- a/html/lag.js +++ b/html/lag.js @@ -3,7 +3,6 @@ var lagInterval = Number(); function lagForm() { if (!numPorts) return; - clearInterval(lagInterval); for (let j=0; j < 4; j++) { var lag = "mLAG" + j console.log("Adding LAG " + lag) @@ -35,9 +34,6 @@ function setL(p, c){ console.log("LAG setting: ", p, " to ", c); document.getElementById(p).checked=c; } -window.addEventListener("load", function() { - lagInterval = setInterval(lagForm, 200); -}); function fetchLag() { var xhttp = new XMLHttpRequest(); @@ -58,7 +54,7 @@ function fetchLag() { } }; xhttp.open("GET", `/lag.json`, true); - xhttp.send(); + sendXHTTP(xhttp); } async function lagSub(l) { var cmd = "lag " + l; @@ -76,3 +72,10 @@ async function lagSub(l) { console.error(`Error: ${err}`); } } + +window.addEventListener("load", function() { + update( () => { + lagForm(); + const interval = setInterval(update, 2000); + }); +}); diff --git a/html/main.js b/html/main.js index 6c05550..085db57 100644 --- a/html/main.js +++ b/html/main.js @@ -9,6 +9,8 @@ var pAdvertised = new Int8Array(10); var numPorts = 0; var logToPhysPort = new Int8Array(10); var physToLogPort = new Int8Array(10); +var currentRequests = []; +var currentCallback; function drawPorts() { var f = document.getElementById('ports'); console.log("DRAWING PORTS: ", numPorts); @@ -38,9 +40,10 @@ function drawPorts() { } } -function update() { +function update(callback) { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { + console.log("IN UPDATE "); if (this.readyState == 4 && this.status == 401) document.location = "/login.html" if (this.readyState == 4 && this.status == 200) { @@ -105,13 +108,40 @@ function update() { tt.innerHTML = iHTML; } } + if (callback) + callback(); } }; xhttp.open("GET", "/status.json", true); - xhttp.timeout = 5000; xhttp.send(); + xhttp.timeout = 5000; + sendXHTTP(xhttp); +} + +function callbackXHTTP() +{ + x = currentRequests.shift(); + x.onreadystatechange = currentCallback; + x.onreadystatechange(); + if (currentRequests.length === 0) + return; + x = currentRequests[0]; + currentCallback = x.onreadystatechange; + x.onreadystatechange = callbackXHTTP; + setTimeout(() => { + x.send(); + }, 20); +} + +function sendXHTTP(x) +{ + console.log("sendXHTTP ", x); + if (currentRequests.length === 0) { + currentRequests.push(x); + currentCallback = x.onreadystatechange; + x.onreadystatechange = callbackXHTTP; + x.send(); + return; + } + currentRequests.push(x); } -window.addEventListener("load", function() { - update(); - const interval = setInterval(update, 2000); -}); diff --git a/html/mirror.js b/html/mirror.js index b66df15..d09a7b0 100644 --- a/html/mirror.js +++ b/html/mirror.js @@ -4,7 +4,6 @@ const mirrors = ["mPortsTX", "mPortsRX"]; function mirrorForm() { if (!numPorts) return; - clearInterval(mirrorInterval); for (let j=0; j < mirrors.length; j++) { console.log("Adding Mirror " + j) var m = document.getElementById(mirrors[j]); @@ -34,9 +33,6 @@ function mirrorForm() { function setM(p, c){ document.getElementById(p).checked=c; } -window.addEventListener("load", function() { - mirrorInterval = setInterval(mirrorForm, 200); -}); function fetchMirror() { var xhttp = new XMLHttpRequest(); @@ -51,11 +47,18 @@ function fetchMirror() { for (let i = 1; i <= numPorts; i++) { let p = i - 1; if (numPorts < 9) - p = physToLogPort[p];members & (1< { + mirrorForm(); + const interval = setInterval(update, 2000); + }); +}); diff --git a/html/ports.js b/html/ports.js index 257f397..dedd741 100644 --- a/html/ports.js +++ b/html/ports.js @@ -3,7 +3,6 @@ var clicked = new Int8Array(10); function createPortTable() { var tbl = document.getElementById('speedtable'); if (tbl.rows.length <= 2 && numPorts) { - clearInterval(pTableInterval); const sSelect = '