v1.3.0.1 (Epic Store release)
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Barotrauma.Extensions;
|
||||
|
||||
#if SERVER
|
||||
using PipeType = System.IO.Pipes.AnonymousPipeClientStream;
|
||||
@@ -121,6 +121,7 @@ namespace Barotrauma.Networking
|
||||
readCancellationToken?.Cancel();
|
||||
return Option<int>.None();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (readTask.IsCompleted || readTask.Wait(timeOutMilliseconds, readCancellationToken.Token))
|
||||
@@ -327,7 +328,36 @@ namespace Barotrauma.Networking
|
||||
writeManualResetEvent.Set();
|
||||
}
|
||||
|
||||
public static bool Read(out byte[] msg)
|
||||
private static readonly Stopwatch stopwatch = new Stopwatch();
|
||||
private const int MaxMilliseconds = 8;
|
||||
|
||||
public static IEnumerable<byte[]> Read()
|
||||
{
|
||||
stopwatch.Restart();
|
||||
|
||||
// To avoid the stopwatch somehow experiencing magical overhead that makes it not even
|
||||
// start the loop within 8ms, use this bool to force at least one iteration.
|
||||
bool hasIteratedAtLeastOnce = false;
|
||||
|
||||
// If it's taken more than 8 milliseconds to read dequeued messages, take
|
||||
// a break from reading and allow all of the other logic to run for a tick.
|
||||
// Otherwise the server may overwhelm the host client with redundant messages
|
||||
// that are being read too slowly.
|
||||
while (!hasIteratedAtLeastOnce || stopwatch.ElapsedMilliseconds < MaxMilliseconds)
|
||||
{
|
||||
hasIteratedAtLeastOnce = true;
|
||||
if (!ReadSingleMessage(out var msg))
|
||||
{
|
||||
// No more messages available to dequeue, we don't need
|
||||
// to reach 8 milliseconds to know we're done here
|
||||
break;
|
||||
}
|
||||
yield return msg;
|
||||
}
|
||||
stopwatch.Stop();
|
||||
}
|
||||
|
||||
private static bool ReadSingleMessage(out byte[] msg)
|
||||
{
|
||||
if (HasShutDown) { msg = null; return false; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user