/// <summary> /// 断开连接 /// </summary> public override void Disconnect() { if (!this.Connected) { return; } this.Connected = false; this.OnDisconnected?.Invoke(this); ConnectSender.SendFIN(this.SendParser.Packet, this.NetSocket, this.RemoteEndPoint, this.Id); //服务端连接断开把缓冲区丢进池 if (this.NetService.ServiceType == NetServiceType.Server) { ParserStorage.Push(this.SendParser); ParserStorage.Push(this.RecvParser); } else { this.SendParser.Clear(); this.RecvParser.Clear(); } KCP.KcpRelease(this.Kcp); this.Kcp = IntPtr.Zero; }
public async override void Disconnect() { if (!this.Connected) { return; } if (NetSocket == null) { return; } this.Connected = false; //服务端连接断开把缓冲区丢进池 if (this.NetService.ServiceType == NetServiceType.Server) { ParserStorage.Push(SendParser); ParserStorage.Push(RecvParser); } else { this.SendParser.Clear(); this.RecvParser.Clear(); } await SendClose(this.NetSocket); await this.SyncContext; this.OnDisconnected(this); }
public override void Disconnect() { if (!this.Connected) { return; } if (this.NetSocket == null) { return; } this.Connected = false; this.OnDisconnected?.Invoke(this); //服务端连接断开把缓冲区丢进池 if (this.NetService.ServiceType == NetServiceType.Server) { ParserStorage.Push(this.SendParser); ParserStorage.Push(this.RecvParser); } else { this.SendParser.Clear(); this.RecvParser.Clear(); } this.NetSocket.Close(); this.NetSocket.Dispose(); this.NetSocket = null; this.InArgs.Dispose(); this.OutArgs.Dispose(); }