未验证 提交 a6703ecb 编写于 作者: A Asher

Prevent sending disconnect if disposed

上级 57a8186e
......@@ -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 sendDisconnect(): void {
if (!this.disposed) {
super.sendDisconnect();
}
}
public dispose(error?: Error): void {
if (error) {
this.sendMessage({ type: "error", reason: error.message });
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();
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册