Prevent sending disconnect if disposed

This commit is contained in:
Asher 2019-07-02 11:33:37 -05:00
parent 57a8186e88
commit a6703ecb98
No known key found for this signature in database
GPG Key ID: D63C1EF81242354A

View File

@ -13,6 +13,8 @@ export interface SocketOptions {
} }
export class Protocol extends PersistentProtocol { export class Protocol extends PersistentProtocol {
private disposed: boolean = false;
public constructor( public constructor(
secWebsocketKey: string, secWebsocketKey: string,
socket: net.Socket, socket: net.Socket,
@ -40,12 +42,21 @@ export class Protocol extends PersistentProtocol {
].join("\r\n") + "\r\n\r\n"); ].join("\r\n") + "\r\n\r\n");
} }
public dispose(error?: Error): void { public sendDisconnect(): void {
if (error) { if (!this.disposed) {
this.sendMessage({ type: "error", reason: error.message }); super.sendDisconnect();
}
}
public dispose(error?: Error): void {
if (!this.disposed) {
this.disposed = true;
if (error) {
this.sendMessage({ type: "error", reason: error.message });
}
super.dispose();
this.getSocket().dispose();
} }
super.dispose();
this.getSocket().dispose();
} }
/** /**