This commit is contained in:
CortexCore
2024-06-22 17:58:05 +08:00
parent 46b2da988e
commit 07b6fbc2f3
9 changed files with 256 additions and 6 deletions

View File

@@ -40,6 +40,7 @@ namespace BITKit.Net
private readonly ConcurrentDictionary<int,DateTime> _lastHeartbeat = new();
private readonly ConcurrentQueue<(int id,byte[] bytes)> _sendQueue = new();
private readonly ConcurrentDictionary<int,int> _dropCount = new();
private DateTime _now=DateTime.Now;
private TimeSpan _interval=TimeSpan.FromSeconds(0.32);
@@ -91,6 +92,7 @@ namespace BITKit.Net
//BIT4Log.Log<KCPNetServer>($"{Name}目前有{server.connections.Count}个链接");
_dropCount.Clear();
while (_sendQueue.TryDequeue(out var value))
{
@@ -100,9 +102,15 @@ namespace BITKit.Net
}
else
{
BIT4Log.Log<KCPNetServer>($"链接{value.id}已丢失,丢弃了{value.bytes.Length}个字节");
int UpdateValueFactory(int i, int i1) => i1 + value.bytes.Length;
_dropCount.AddOrUpdate(value.id,value.bytes.Length,UpdateValueFactory);
}
}
foreach (var (id,length) in _dropCount)
{
BIT4Log.Log<KCPNetServer>($"未找到链接:{id},已丢弃字节数量:{length}");
}
}
catch (SocketException)
{
@@ -114,6 +122,8 @@ namespace BITKit.Net
}
}
public void StartServer(ushort port = 27014)
{
if (IsRunningServer is false)