From 52a24f979b5945891583d630c0bfa2cf20069a1c Mon Sep 17 00:00:00 2001 From: sin365 <353374337@qq.com> Date: Mon, 18 Dec 2023 14:37:58 +0800 Subject: [PATCH] fix --- .../NetWork/TcpSaeaServer.cs | 24 ++++++++----------- Simple/ClientCore/Network/NetworkHelper.cs | 2 +- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/NetLib/HaoYueNet.ServerNetwork/NetWork/TcpSaeaServer.cs b/NetLib/HaoYueNet.ServerNetwork/NetWork/TcpSaeaServer.cs index 270222b..130c118 100644 --- a/NetLib/HaoYueNet.ServerNetwork/NetWork/TcpSaeaServer.cs +++ b/NetLib/HaoYueNet.ServerNetwork/NetWork/TcpSaeaServer.cs @@ -234,20 +234,13 @@ namespace HaoYueNet.ServerNetwork private void CloseClientSocket(SocketAsyncEventArgs e) { AsyncUserToken token = e.UserToken as AsyncUserToken; - //调用关闭连接 OnDisconnected?.Invoke(token); - RemoveUserToken(token); - //如果有事件,则调用事件,发送客户端数量变化通知 OnClientNumberChange?.Invoke(-1, token); - // close the socket associated with the client - try - { - token.Socket.Shutdown(SocketShutdown.Send); - } + try { token.Socket.Shutdown(SocketShutdown.Send); } catch (Exception) { } token.Socket.Close(); // decrement the counter keeping track of the total number of clients connected to the server @@ -496,8 +489,11 @@ namespace HaoYueNet.ServerNetwork /// void ReleaseSocketAsyncEventArgs(SocketAsyncEventArgs saea) { - saea.UserToken = null;//TODO - saea.SetBuffer(null, 0, 0); + //saea.UserToken = null;//TODO + //saea.SetBuffer(null, 0, 0); + //saea.Dispose(); + //↑ 这里不要自作主张去清东西,否则回收回去不可用 + switch (saea.LastOperation) { case SocketAsyncOperation.Receive: @@ -506,7 +502,10 @@ namespace HaoYueNet.ServerNetwork case SocketAsyncOperation.Send: m_Sendpool.Push(saea); break; + default: + throw new ArgumentException("ReleaseSocketAsyncEventArgs > The last operation completed on the socket was not a receive or send"); } + } int sendrun = 0; @@ -602,16 +601,13 @@ namespace HaoYueNet.ServerNetwork return HeadAndBody; } - #region + #region private void OnCloseReady(AsyncUserToken token) { OnDisconnected?.Invoke(token); - RemoveUserToken(token); - //如果有事件,则调用事件,发送客户端数量变化通知 OnClientNumberChange?.Invoke(-1, token); - // close the socket associated with the client try { diff --git a/Simple/ClientCore/Network/NetworkHelper.cs b/Simple/ClientCore/Network/NetworkHelper.cs index 3ef9407..dd33bea 100644 --- a/Simple/ClientCore/Network/NetworkHelper.cs +++ b/Simple/ClientCore/Network/NetworkHelper.cs @@ -32,7 +32,7 @@ namespace ClientCore.Network /// /// 是否自动重连 /// - public bool bAutoReConnect = true; + public bool bAutoReConnect = false; /// /// 重连尝试时间 ///