fix: on write and end, log errors if we are trying to use a closed socket

This commit is contained in:
Derrick Hammer 2023-07-22 07:11:48 -04:00
parent 7eabf6a05d
commit 57efedd0af
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 11 additions and 2 deletions

View File

@ -229,15 +229,24 @@ export class Socket extends Client {
}
write(message: string | Buffer): void {
this.callModule("socketExists", { id: this.id }).then(
([exists]: ErrTuple) => {
if (!exists) {
logErr("tried to write to closed socket");
}
this.callModule("socketWrite", { id: this.id, message });
},
);
this.callModule("socketWrite", { id: this.id, message });
}
end(): void {
this.callModule("socketExists", { id: this.id }).then(
([exists]: ErrTuple) => {
if (exists) {
this.callModule("socketClose", { id: this.id });
if (!exists) {
logErr("tried to close a closed socket");
}
this.callModule("socketClose", { id: this.id });
},
);
}