fix(core): Tightens the network stack (#479)
- [X] Removes network pause/resume - [X] Adds back packet profiler - [X] Adds state machine to keep track and trace netstates - [X] Changes NetState.Running back to using an interlock exchange - [X] Adds preliminary packet throttling support ### Packet Throttling - `[GetThrottle <packetId>` to get the delay in milliseconds for that packet - `[SetThrottle <packetId> <delay>` to set the delay in milliseconds for that packet The settings are saved to `Configuration/throttles.json`
This commit is contained in:
parent
1736469ac0
commit
8903028b5f
36 changed files with 1018 additions and 405 deletions
|
|
@ -212,7 +212,24 @@ namespace Server.Network
|
|||
{
|
||||
_pipe._closed = true;
|
||||
|
||||
Flush();
|
||||
var waiting = _pipe._readAwaitBeginning;
|
||||
|
||||
if (!waiting)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Action continuation;
|
||||
|
||||
do
|
||||
{
|
||||
continuation = _pipe._readContinuation;
|
||||
} while (continuation == null);
|
||||
|
||||
_pipe._readContinuation = null;
|
||||
_pipe._readAwaitBeginning = false;
|
||||
|
||||
ThreadPool.UnsafeQueueUserWorkItem(_ => continuation(), true);
|
||||
}
|
||||
|
||||
public void Flush()
|
||||
|
|
@ -257,6 +274,11 @@ namespace Server.Network
|
|||
return true;
|
||||
}
|
||||
|
||||
if (_pipe._closed)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
_pipe._writeAwaitBeginning = true;
|
||||
return false;
|
||||
}
|
||||
|
|
@ -363,7 +385,7 @@ namespace Server.Network
|
|||
|
||||
public void Commit()
|
||||
{
|
||||
if (_pipe._readIdx == (_pipe._writeIdx + 1) % _pipe.Size)
|
||||
if (_pipe._readIdx == ((_pipe._writeIdx + 1) & (_pipe.Size - 1)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -388,6 +410,30 @@ namespace Server.Network
|
|||
ThreadPool.UnsafeQueueUserWorkItem(_ => continuation(), true);
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
_pipe._closed = true;
|
||||
|
||||
var waiting = _pipe._writeAwaitBeginning;
|
||||
|
||||
if (!waiting)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Action continuation;
|
||||
|
||||
do
|
||||
{
|
||||
continuation = _pipe._writeContinuation;
|
||||
} while (continuation == null);
|
||||
|
||||
_pipe._writeContinuation = null;
|
||||
_pipe._readAwaitBeginning = false;
|
||||
|
||||
ThreadPool.UnsafeQueueUserWorkItem(_ => continuation(), true);
|
||||
}
|
||||
|
||||
#region Awaitable
|
||||
|
||||
// The following makes it possible to await the reader. Do not use any of this directly.
|
||||
|
|
@ -403,6 +449,11 @@ namespace Server.Network
|
|||
return true;
|
||||
}
|
||||
|
||||
if (_pipe._closed)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
_pipe._readAwaitBeginning = true;
|
||||
return false;
|
||||
}
|
||||
|
|
@ -427,6 +478,12 @@ namespace Server.Network
|
|||
|
||||
public Pipe(T[] buf)
|
||||
{
|
||||
// Test if the buffer is a power of two
|
||||
if (buf.Length == 0 || (buf.Length & (buf.Length - 1)) != 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(buf), "Pipe buffers must have a length that is a power of two");
|
||||
}
|
||||
|
||||
_buffer = buf;
|
||||
_writeIdx = 0;
|
||||
_readIdx = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue