This commit is contained in:
Mikko Ahlroth 2024-07-18 01:29:24 +03:00
parent 36e28ef081
commit b466a6b2a2

View file

@ -122,6 +122,7 @@ class Connection {
/** @type {NodeJS.Timer | null} */
reachabilityTimeout = null;
connected = false;
writing = false;
/**
@ -136,14 +137,22 @@ class Connection {
}
initTargetSocket() {
this.connected = false;
clearTimeout(this.retryTimeout);
this.writeSocket.on("connect", () => {
this.connected = true;
console.log(
"Opened new connection to target from",
this.source.address,
this.source.port
);
if (this.msgBuffer.length > 0) {
requestIdleCallback(() => {
this.send();
});
}
});
this.writeSocket.on("message", (fromMsg) => {
this.#resetIdleTimeout();
@ -180,7 +189,7 @@ class Connection {
send(msg) {
this.#resetIdleTimeout();
if (msg && (this.writing || !this.writeSocket)) {
if (msg && (!this.connected || this.writing || !this.writeSocket)) {
this.msgBuffer.push(msg);
return;
}