Prevent sending disconnect if disposed
This commit is contained in:
parent
57a8186e88
commit
a6703ecb98
11
protocol.ts
11
protocol.ts
|
@ -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,13 +42,22 @@ export class Protocol extends PersistentProtocol {
|
||||||
].join("\r\n") + "\r\n\r\n");
|
].join("\r\n") + "\r\n\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public sendDisconnect(): void {
|
||||||
|
if (!this.disposed) {
|
||||||
|
super.sendDisconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public dispose(error?: Error): void {
|
public dispose(error?: Error): void {
|
||||||
|
if (!this.disposed) {
|
||||||
|
this.disposed = true;
|
||||||
if (error) {
|
if (error) {
|
||||||
this.sendMessage({ type: "error", reason: error.message });
|
this.sendMessage({ type: "error", reason: error.message });
|
||||||
}
|
}
|
||||||
super.dispose();
|
super.dispose();
|
||||||
this.getSocket().dispose();
|
this.getSocket().dispose();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform a handshake to get a connection request.
|
* Perform a handshake to get a connection request.
|
||||||
|
|
Loading…
Reference in New Issue