This commit is contained in:
sin365 2023-12-18 14:37:58 +08:00
parent 7dd00b0936
commit 52a24f979b
2 changed files with 11 additions and 15 deletions

View File

@ -234,20 +234,13 @@ namespace HaoYueNet.ServerNetwork
private void CloseClientSocket(SocketAsyncEventArgs e) private void CloseClientSocket(SocketAsyncEventArgs e)
{ {
AsyncUserToken token = e.UserToken as AsyncUserToken; AsyncUserToken token = e.UserToken as AsyncUserToken;
//调用关闭连接 //调用关闭连接
OnDisconnected?.Invoke(token); OnDisconnected?.Invoke(token);
RemoveUserToken(token); RemoveUserToken(token);
//如果有事件,则调用事件,发送客户端数量变化通知 //如果有事件,则调用事件,发送客户端数量变化通知
OnClientNumberChange?.Invoke(-1, token); OnClientNumberChange?.Invoke(-1, token);
// close the socket associated with the client // close the socket associated with the client
try try { token.Socket.Shutdown(SocketShutdown.Send); }
{
token.Socket.Shutdown(SocketShutdown.Send);
}
catch (Exception) { } catch (Exception) { }
token.Socket.Close(); token.Socket.Close();
// decrement the counter keeping track of the total number of clients connected to the server // decrement the counter keeping track of the total number of clients connected to the server
@ -496,8 +489,11 @@ namespace HaoYueNet.ServerNetwork
/// <param name="saea"></param> /// <param name="saea"></param>
void ReleaseSocketAsyncEventArgs(SocketAsyncEventArgs saea) void ReleaseSocketAsyncEventArgs(SocketAsyncEventArgs saea)
{ {
saea.UserToken = null;//TODO //saea.UserToken = null;//TODO
saea.SetBuffer(null, 0, 0); //saea.SetBuffer(null, 0, 0);
//saea.Dispose();
//↑ 这里不要自作主张去清东西,否则回收回去不可用
switch (saea.LastOperation) switch (saea.LastOperation)
{ {
case SocketAsyncOperation.Receive: case SocketAsyncOperation.Receive:
@ -506,7 +502,10 @@ namespace HaoYueNet.ServerNetwork
case SocketAsyncOperation.Send: case SocketAsyncOperation.Send:
m_Sendpool.Push(saea); m_Sendpool.Push(saea);
break; break;
default:
throw new ArgumentException("ReleaseSocketAsyncEventArgs > The last operation completed on the socket was not a receive or send");
} }
} }
int sendrun = 0; int sendrun = 0;
@ -606,12 +605,9 @@ namespace HaoYueNet.ServerNetwork
private void OnCloseReady(AsyncUserToken token) private void OnCloseReady(AsyncUserToken token)
{ {
OnDisconnected?.Invoke(token); OnDisconnected?.Invoke(token);
RemoveUserToken(token); RemoveUserToken(token);
//如果有事件,则调用事件,发送客户端数量变化通知 //如果有事件,则调用事件,发送客户端数量变化通知
OnClientNumberChange?.Invoke(-1, token); OnClientNumberChange?.Invoke(-1, token);
// close the socket associated with the client // close the socket associated with the client
try try
{ {

View File

@ -32,7 +32,7 @@ namespace ClientCore.Network
/// <summary> /// <summary>
/// 是否自动重连 /// 是否自动重连
/// </summary> /// </summary>
public bool bAutoReConnect = true; public bool bAutoReConnect = false;
/// <summary> /// <summary>
/// 重连尝试时间 /// 重连尝试时间
/// </summary> /// </summary>