Prevent sending disconnect if disposed
This commit is contained in:
parent
57a8186e88
commit
a6703ecb98
21
protocol.ts
21
protocol.ts
|
@ -13,6 +13,8 @@ export interface SocketOptions {
|
|||
}
|
||||
|
||||
export class Protocol extends PersistentProtocol {
|
||||
private disposed: boolean = false;
|
||||
|
||||
public constructor(
|
||||
secWebsocketKey: string,
|
||||
socket: net.Socket,
|
||||
|
@ -40,12 +42,21 @@ export class Protocol extends PersistentProtocol {
|
|||
].join("\r\n") + "\r\n\r\n");
|
||||
}
|
||||
|
||||
public dispose(error?: Error): void {
|
||||
if (error) {
|
||||
this.sendMessage({ type: "error", reason: error.message });
|
||||
public sendDisconnect(): void {
|
||||
if (!this.disposed) {
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue