From 2e3940e8f54164af3e07af0952eea64f4fd8de36 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 11 Oct 2020 12:22:52 +0100 Subject: [PATCH] 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. --- src/network/mcpe/NetworkSession.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/network/mcpe/NetworkSession.php b/src/network/mcpe/NetworkSession.php index 461062056..214cc7863 100644 --- a/src/network/mcpe/NetworkSession.php +++ b/src/network/mcpe/NetworkSession.php @@ -427,7 +427,7 @@ class NetworkSession{ if(count($this->sendBuffer) > 0){ $promise = $this->server->prepareBatch(PacketBatch::fromPackets(...$this->sendBuffer), $this->compressor, $immediate); $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{ $this->flushSendBuffer($immediate); //Maintain ordering if possible + $this->queueCompressedNoBufferFlush($payload, $immediate); + } + + private function queueCompressedNoBufferFlush(CompressBatchPromise $payload, bool $immediate = false) : void{ if($immediate){ //Skips all queues $this->sendEncoded($payload->getResult(), true);