Control xhttp concurrency

This commit is contained in:
logicog
2026-03-10 06:16:18 +01:00
parent c2f5a91763
commit fa37940075
10 changed files with 106 additions and 45 deletions
+6 -4
View File
@@ -3,7 +3,6 @@ function createBW() {
var tbl = document.getElementById('bwtable'); var tbl = document.getElementById('bwtable');
const limit = '<input type="checkbox" id="limit_port" onchange="exec();">' const limit = '<input type="checkbox" id="limit_port" onchange="exec();">'
if (tbl.rows.length <= 2 && numPorts) { if (tbl.rows.length <= 2 && numPorts) {
clearInterval(createBWInterval);
console.log("CREATING TABLE ", tbl.rows.length); console.log("CREATING TABLE ", tbl.rows.length);
for (let i = 2; i < 2 + numPorts; i++) { for (let i = 2; i < 2 + numPorts; i++) {
const tr = tbl.insertRow(); const tr = tbl.insertRow();
@@ -94,6 +93,7 @@ async function applyBandwidth(i) {
function getBW() { function getBW() {
var xhttp = new XMLHttpRequest(); var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() { xhttp.onreadystatechange = function() {
console.log("IN getBW ");
if (this.readyState == 4 && this.status == 200) { if (this.readyState == 4 && this.status == 200) {
const s = JSON.parse(xhttp.responseText); const s = JSON.parse(xhttp.responseText);
console.log("BW: ", JSON.stringify(s)); console.log("BW: ", JSON.stringify(s));
@@ -126,11 +126,13 @@ function getBW() {
} }
}; };
xhttp.open("GET", "/bandwidth.json", true); xhttp.open("GET", "/bandwidth.json", true);
xhttp.timeout = 1500; xhttp.send(); xhttp.timeout = 1500; sendXHTTP(xhttp);
} }
window.addEventListener("load", function() { window.addEventListener("load", function() {
update( () => {
createBW();
getBW(); getBW();
const iCount = setInterval(getBW, 2000); const interval = setInterval(update, 2000);
});
}); });
const createBWInterval = setInterval(createBW, 1010);
+5 -3
View File
@@ -1,7 +1,6 @@
function createEEE() { function createEEE() {
var tbl = document.getElementById('eeetable'); var tbl = document.getElementById('eeetable');
if (tbl.rows.length <= 2 && numPorts) { if (tbl.rows.length <= 2 && numPorts) {
clearInterval(createEEEInterval);
console.log("CREATING TABLE ", tbl.rows.length); console.log("CREATING TABLE ", tbl.rows.length);
for (let i = 2; i < 2 + numPorts; i++) { for (let i = 2; i < 2 + numPorts; i++) {
console.log("Table row: " + i + "pState: " + pState[i-2]); console.log("Table row: " + i + "pState: " + pState[i-2]);
@@ -40,11 +39,14 @@ function getEEE() {
} }
}; };
xhttp.open("GET", "/eee.json", true); xhttp.open("GET", "/eee.json", true);
xhttp.timeout = 1500; xhttp.send(); xhttp.timeout = 1500; sendXHTTP(xhttp);
} }
window.addEventListener("load", function() { window.addEventListener("load", function() {
update( () => {
createEEE();
getEEE(); getEEE();
const interval = setInterval(update, 2000);
const iCount = setInterval(getEEE, 2000); const iCount = setInterval(getEEE, 2000);
});
}); });
const createEEEInterval = setInterval(createEEE, 1000);
+7
View File
@@ -2,6 +2,13 @@
<html> <html>
<script src="/main.js"></script> <script src="/main.js"></script>
<script src="/main_info.js"></script> <script src="/main_info.js"></script>
<script>
window.addEventListener("load", function() {
update( () => {
const interval = setInterval(update, 2000);
});
});
</script>
<link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="style.css">
<title>FreeSwitchOS Main Page</title> <title>FreeSwitchOS Main Page</title>
</head> </head>
+5 -1
View File
@@ -130,10 +130,14 @@ function getL2() {
} }
}; };
xhttp.open("GET", "/l2.json?idx=" + l2CurrentEntry, true); xhttp.open("GET", "/l2.json?idx=" + l2CurrentEntry, true);
xhttp.timeout = 1500; xhttp.send(); xhttp.timeout = 1500; sendXHTTP(xhttp);
} }
window.addEventListener("load", function() { window.addEventListener("load", function() {
update( () => {
getL2();
const interval = setInterval(update, 2000);
l2GetInterval = setInterval(getL2, 1000); l2GetInterval = setInterval(getL2, 1000);
});;
}); });
+8 -5
View File
@@ -3,7 +3,6 @@ var lagInterval = Number();
function lagForm() { function lagForm() {
if (!numPorts) if (!numPorts)
return; return;
clearInterval(lagInterval);
for (let j=0; j < 4; j++) { for (let j=0; j < 4; j++) {
var lag = "mLAG" + j var lag = "mLAG" + j
console.log("Adding LAG " + lag) console.log("Adding LAG " + lag)
@@ -35,9 +34,6 @@ function setL(p, c){
console.log("LAG setting: ", p, " to ", c); console.log("LAG setting: ", p, " to ", c);
document.getElementById(p).checked=c; document.getElementById(p).checked=c;
} }
window.addEventListener("load", function() {
lagInterval = setInterval(lagForm, 200);
});
function fetchLag() { function fetchLag() {
var xhttp = new XMLHttpRequest(); var xhttp = new XMLHttpRequest();
@@ -58,7 +54,7 @@ function fetchLag() {
} }
}; };
xhttp.open("GET", `/lag.json`, true); xhttp.open("GET", `/lag.json`, true);
xhttp.send(); sendXHTTP(xhttp);
} }
async function lagSub(l) { async function lagSub(l) {
var cmd = "lag " + l; var cmd = "lag " + l;
@@ -76,3 +72,10 @@ async function lagSub(l) {
console.error(`Error: ${err}`); console.error(`Error: ${err}`);
} }
} }
window.addEventListener("load", function() {
update( () => {
lagForm();
const interval = setInterval(update, 2000);
});
});
+36 -6
View File
@@ -9,6 +9,8 @@ var pAdvertised = new Int8Array(10);
var numPorts = 0; var numPorts = 0;
var logToPhysPort = new Int8Array(10); var logToPhysPort = new Int8Array(10);
var physToLogPort = new Int8Array(10); var physToLogPort = new Int8Array(10);
var currentRequests = [];
var currentCallback;
function drawPorts() { function drawPorts() {
var f = document.getElementById('ports'); var f = document.getElementById('ports');
console.log("DRAWING PORTS: ", numPorts); console.log("DRAWING PORTS: ", numPorts);
@@ -38,9 +40,10 @@ function drawPorts() {
} }
} }
function update() { function update(callback) {
var xhttp = new XMLHttpRequest(); var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() { xhttp.onreadystatechange = function() {
console.log("IN UPDATE ");
if (this.readyState == 4 && this.status == 401) if (this.readyState == 4 && this.status == 401)
document.location = "/login.html" document.location = "/login.html"
if (this.readyState == 4 && this.status == 200) { if (this.readyState == 4 && this.status == 200) {
@@ -105,13 +108,40 @@ function update() {
tt.innerHTML = iHTML; tt.innerHTML = iHTML;
} }
} }
if (callback)
callback();
} }
}; };
xhttp.open("GET", "/status.json", true); 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);
});
+9 -6
View File
@@ -4,7 +4,6 @@ const mirrors = ["mPortsTX", "mPortsRX"];
function mirrorForm() { function mirrorForm() {
if (!numPorts) if (!numPorts)
return; return;
clearInterval(mirrorInterval);
for (let j=0; j < mirrors.length; j++) { for (let j=0; j < mirrors.length; j++) {
console.log("Adding Mirror " + j) console.log("Adding Mirror " + j)
var m = document.getElementById(mirrors[j]); var m = document.getElementById(mirrors[j]);
@@ -34,9 +33,6 @@ function mirrorForm() {
function setM(p, c){ function setM(p, c){
document.getElementById(p).checked=c; document.getElementById(p).checked=c;
} }
window.addEventListener("load", function() {
mirrorInterval = setInterval(mirrorForm, 200);
});
function fetchMirror() { function fetchMirror() {
var xhttp = new XMLHttpRequest(); var xhttp = new XMLHttpRequest();
@@ -51,11 +47,18 @@ function fetchMirror() {
for (let i = 1; i <= numPorts; i++) { for (let i = 1; i <= numPorts; i++) {
let p = i - 1; let p = i - 1;
if (numPorts < 9) if (numPorts < 9)
p = physToLogPort[p];members & (1<<p) p = physToLogPort[p];
setM("mPortsTX"+i, m_tx&(1<<p)); setM("mPortsRX"+i, m_rx&(1<<p)); setM("mPortsTX"+i, m_tx&(1<<p)); setM("mPortsRX"+i, m_rx&(1<<p));
} }
} }
}; };
xhttp.open("GET", `/mirror.json`, true); xhttp.open("GET", `/mirror.json`, true);
xhttp.send(); sendXHTTP(xhttp);
} }
window.addEventListener("load", function() {
update( () => {
mirrorForm();
const interval = setInterval(update, 2000);
});
});
+7 -6
View File
@@ -3,7 +3,6 @@ var clicked = new Int8Array(10);
function createPortTable() { function createPortTable() {
var tbl = document.getElementById('speedtable'); var tbl = document.getElementById('speedtable');
if (tbl.rows.length <= 2 && numPorts) { if (tbl.rows.length <= 2 && numPorts) {
clearInterval(pTableInterval);
const sSelect = '<select name="speed_sel" id="speed_sel">' const sSelect = '<select name="speed_sel" id="speed_sel">'
+ '<option value="auto">Auto</option>' + '<option value="auto">Auto</option>'
+ '<option value="2g5">2500MBit/Full</option>' + '<option value="2g5">2500MBit/Full</option>'
@@ -130,17 +129,19 @@ function getMTUs() {
if (!mtu) if (!mtu)
continue; continue;
mtu.value = mtus[n]; mtu.value = mtus[n];
clearInterval(pMTUInterval);
} }
} }
}; };
xhttp.open("GET", "/mtu.json", true); xhttp.open("GET", "/mtu.json", true);
xhttp.timeout = 1500; xhttp.send(); xhttp.timeout = 1500; sendXHTTP(xhttp);
} }
window.addEventListener("load", function() { window.addEventListener("load", function() {
update( () => {
createPortTable();
updatePortTable();
getMTUs()
const interval = setInterval(update, 2000);
const updatePortTableInterval = setInterval(updatePortTable, 1000); const updatePortTableInterval = setInterval(updatePortTable, 1000);
});
}); });
const pTableInterval = setInterval(createPortTable, 1000);
const pMTUInterval = setInterval(getMTUs, 1200);
+10 -3
View File
@@ -151,7 +151,7 @@ function getCounters(port) {
} }
}; };
xhttp.open("GET", "/counters.json?port=" + port, true); xhttp.open("GET", "/counters.json?port=" + port, true);
xhttp.timeout = 1500; xhttp.send(); xhttp.timeout = 1500; sendXHTTP(xhttp);
} }
@@ -184,8 +184,6 @@ function fillStats() {
} }
} }
const stat = setInterval(fillStats, 1000);
const popup = document.getElementById('popup'); const popup = document.getElementById('popup');
const closePopup = document.getElementById('closePopup'); const closePopup = document.getElementById('closePopup');
closePopup.addEventListener('click', () => { closePopup.addEventListener('click', () => {
@@ -196,3 +194,12 @@ window.addEventListener('click', (event) => {
popup.style.display = 'none'; popup.style.display = 'none';
} }
}); });
window.addEventListener("load", function() {
update( () => {
update();
fillStats();
const stat = setInterval(fillStats, 1000);
const interval = setInterval(update, 2000);
});
});
+8 -6
View File
@@ -3,7 +3,6 @@ var vlanInterval = Number();
function vlanForm() { function vlanForm() {
if (!numPorts) if (!numPorts)
return; return;
clearInterval(vlanInterval);
var t = document.getElementById('tPorts'); var t = document.getElementById('tPorts');
var u = document.getElementById('uPorts'); var u = document.getElementById('uPorts');
var p = document.getElementById('pPorts'); var p = document.getElementById('pPorts');
@@ -58,10 +57,6 @@ function pvClicked(p){
} }
} }
window.addEventListener("load", function() {
vlanInterval = setInterval(vlanForm, 100);
});
function fetchVLAN() { function fetchVLAN() {
var xhttp = new XMLHttpRequest(); var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() { xhttp.onreadystatechange = function() {
@@ -83,5 +78,12 @@ function fetchVLAN() {
return; return;
} }
xhttp.open("GET", `/vlan.json?vid=${v}`, true); xhttp.open("GET", `/vlan.json?vid=${v}`, true);
xhttp.send(); sendXHTTP(xhttp);
} }
window.addEventListener("load", function() {
update( () => {
vlanForm();
const interval = setInterval(update, 2000);
});
});