NetworkSession: remove circular dependency between queueCompressed() and flushSendBuffer()

this cycle makes the code fragile and prone to infinite looping bugs when modified, as well as making the code harder to follow.
This commit is contained in:
Dylan K. Taylor 2020-10-11 12:22:52 +01:00
parent 46c57e4e24
commit 2e3940e8f5

View File

@ -427,7 +427,7 @@ class NetworkSession{
if(count($this->sendBuffer) > 0){ if(count($this->sendBuffer) > 0){
$promise = $this->server->prepareBatch(PacketBatch::fromPackets(...$this->sendBuffer), $this->compressor, $immediate); $promise = $this->server->prepareBatch(PacketBatch::fromPackets(...$this->sendBuffer), $this->compressor, $immediate);
$this->sendBuffer = []; $this->sendBuffer = [];
$this->queueCompressed($promise, $immediate); $this->queueCompressedNoBufferFlush($promise, $immediate);
} }
} }
@ -437,6 +437,10 @@ class NetworkSession{
public function queueCompressed(CompressBatchPromise $payload, bool $immediate = false) : void{ public function queueCompressed(CompressBatchPromise $payload, bool $immediate = false) : void{
$this->flushSendBuffer($immediate); //Maintain ordering if possible $this->flushSendBuffer($immediate); //Maintain ordering if possible
$this->queueCompressedNoBufferFlush($payload, $immediate);
}
private function queueCompressedNoBufferFlush(CompressBatchPromise $payload, bool $immediate = false) : void{
if($immediate){ if($immediate){
//Skips all queues //Skips all queues
$this->sendEncoded($payload->getResult(), true); $this->sendEncoded($payload->getResult(), true);