NullSessionHandler: possibly premature optimization

This commit is contained in:
Dylan K. Taylor 2019-05-06 17:28:56 +01:00
parent 685481b172
commit 82974e0271
3 changed files with 12 additions and 3 deletions

View File

@ -420,7 +420,7 @@ class NetworkSession{
$this->disconnectGuard = true; $this->disconnectGuard = true;
$func(); $func();
$this->disconnectGuard = false; $this->disconnectGuard = false;
$this->setHandler(new NullSessionHandler()); $this->setHandler(NullSessionHandler::getInstance());
$this->connected = false; $this->connected = false;
$this->manager->remove($this); $this->manager->remove($this);
} }

View File

@ -117,7 +117,7 @@ class LoginSessionHandler extends SessionHandler{
*/ */
protected function processLogin(LoginPacket $packet, bool $authRequired) : void{ protected function processLogin(LoginPacket $packet, bool $authRequired) : void{
$this->server->getAsyncPool()->submitTask(new ProcessLoginTask($this->session, $packet, $authRequired, NetworkCipher::$ENABLED)); $this->server->getAsyncPool()->submitTask(new ProcessLoginTask($this->session, $packet, $authRequired, NetworkCipher::$ENABLED));
$this->session->setHandler(new NullSessionHandler()); //drop packets received during login verification $this->session->setHandler(NullSessionHandler::getInstance()); //drop packets received during login verification
} }
protected function isCompatibleProtocol(int $protocolVersion) : bool{ protected function isCompatibleProtocol(int $protocolVersion) : bool{

View File

@ -26,6 +26,15 @@ namespace pocketmine\network\mcpe\handler;
/** /**
* Handler which simply ignores all packets received. * Handler which simply ignores all packets received.
*/ */
class NullSessionHandler extends SessionHandler{ final class NullSessionHandler extends SessionHandler{
/** @var self|null */
private static $instance = null;
public static function getInstance() : self{
return self::$instance ?? (self::$instance = new self);
}
private function __construct(){
}
} }