try to fix server bug: couldn't download bitstream

This commit is contained in:
2025-04-22 17:24:46 +08:00
parent 442e40d87a
commit 98a5dbe7f3
6 changed files with 192 additions and 141 deletions

View File

@@ -136,11 +136,11 @@ public class UDPServer
using (await udpData.AcquireWriteLockAsync(timeleft))
{
if (udpData.TryGetValue(ipAddr, out var dataQueue) && dataQueue != null && dataQueue.Count > 0)
if (udpData.ContainsKey(ipAddr) &&
udpData.TryGetValue(ipAddr, out var dataQueue) &&
dataQueue.Count > 0)
{
data = dataQueue.Dequeue();
// data = dataList[0].DeepClone();
// dataList.RemoveAt(0);
logger.Debug($"Find UDP Data: {data.ToString()}");
break;
}
@@ -150,7 +150,7 @@ public class UDPServer
if (data is null)
{
logger.Trace("Get nothing even after time out");
return Optional.None<UDPData>();
return Optional<UDPData>.None;
}
else
{
@@ -179,7 +179,9 @@ public class UDPServer
using (await udpData.AcquireReadLockAsync(timeleft))
{
if (udpData.TryGetValue(ipAddr, out var dataQueue) && dataQueue != null && dataQueue.Count > 0)
if (udpData.ContainsKey(ipAddr) &&
udpData.TryGetValue(ipAddr, out var dataQueue) &&
dataQueue.Count > 0)
{
data = dataQueue.ToList();
logger.Debug($"Find UDP Data Array: {JsonConvert.SerializeObject(data)}");
@@ -191,7 +193,7 @@ public class UDPServer
if (data is null)
{
logger.Trace("Get nothing even after time out");
return Optional.None<List<UDPData>>();
return Optional<List<UDPData>>.None;
}
else
{
@@ -214,7 +216,7 @@ public class UDPServer
throw new Exception("Get None even after time out!");
var recvData = data.Value;
if (recvData.Address != address || (port >= 0 && recvData.Port != port))
if (recvData.Address != address || (port > 0 && recvData.Port != port))
throw new Exception("Receive Data From Wrong Board!");
var retPack = WebProtocol.RecvRespPackage.FromBytes(recvData.Data);
@@ -305,19 +307,13 @@ public class UDPServer
using (udpData.AcquireWriteLock())
{
// Record UDP Receive Data
// if (udpData.ContainsKey(remoteAddress))
if (udpData.TryGetValue(remoteAddress, out var dataQueue))
if (udpData.ContainsKey(remoteAddress) && udpData.TryGetValue(remoteAddress, out var dataQueue))
{
// var listData = udpData[remoteAddress];
// listData.Add(data);
dataQueue.Enqueue(data);
logger.Trace("Receive data from old client");
}
else
{
// var list = new List<UDPData>();
// list.Add(data);
// udpData.Add(remoteAddress, list);
var queue = new Queue<UDPData>();
queue.Enqueue(data);
udpData.Add(remoteAddress, queue);
@@ -401,7 +397,9 @@ public class UDPServer
{
using (await udpData.AcquireWriteLockAsync())
{
if (udpData.TryGetValue(ipAddr, out var dataQueue) && dataQueue.Count > 0)
if (udpData.ContainsKey(ipAddr) &&
udpData.TryGetValue(ipAddr, out var dataQueue) &&
dataQueue.Count > 0)
{
dataQueue.Clear();
}