优化了节点连接

This commit is contained in:
fengjiayi
2024-10-28 15:21:08 +08:00
parent f20cfb755c
commit 561b6d764f
28 changed files with 295 additions and 165 deletions

View File

@@ -123,7 +123,10 @@ namespace Serein.Library.Network.WebSocketCommunication.Handle
catch (Exception ex)
{
Console.WriteLine($"error in ws : {ex.Message}{Environment.NewLine}json value:{jsonObject}");
return;
}
finally
{
context.Handle = true;
}
}

View File

@@ -11,7 +11,7 @@ namespace Serein.Library.Network.WebSocketCommunication.Handle
/// <summary>
/// 消息处理上下文
/// </summary>
public class WebSocketMsgContext : IDisposable
public class WebSocketMsgContext /*: IDisposable*/
{
public WebSocketMsgContext(Func<string, Task> sendAsync)
{
@@ -31,7 +31,14 @@ namespace Serein.Library.Network.WebSocketCommunication.Handle
/// <summary>
/// 标记是否已经处理,如果是,则提前退出
/// </summary>
public bool Handle { get; set; }
public bool Handle { get => _handle; set{
if(value)
{
Dispose();
_handle = value;
}
} }
public bool _handle = false;
/// <summary>
/// 消息本体JObject

View File

@@ -201,13 +201,18 @@ namespace Serein.Library.Network.WebSocketCommunication.Handle
/// </summary>
/// <param name="context">此次请求的上下文</param>
/// <returns></returns>
public async Task HandleAsync(WebSocketMsgContext context)
public void Handle(WebSocketMsgContext context)
{
foreach (var module in MyHandleModuleDict.Values)
{
await module.HandleAsync(context);
if (context.Handle)
{
return;
}
_ = module.HandleAsync(context);
}
}