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