From 1bb2d162ab93f1430cb1511b01e4009e5906caea Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 16 Mar 2021 21:42:18 +0000 Subject: [PATCH] Simplify CommandReader while stream_select() doesn't work on pipes, if it ever starts working properly in the future, we'll need this code. In the meantime, it's harmless (it just immediately returns 1 anyway). --- src/pocketmine/command/CommandReader.php | 41 +++++++++--------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/src/pocketmine/command/CommandReader.php b/src/pocketmine/command/CommandReader.php index 10970d64b..2486cb740 100644 --- a/src/pocketmine/command/CommandReader.php +++ b/src/pocketmine/command/CommandReader.php @@ -116,37 +116,28 @@ class CommandReader extends Thread{ * @return bool if the main execution should continue reading lines */ private function readLine() : bool{ - $line = ""; - if(!is_resource(self::$stdin)){ $this->initStdin(); } - switch($this->type){ - /** @noinspection PhpMissingBreakStatementInspection */ - case self::TYPE_STREAM: - //stream_select doesn't work on piped streams for some reason - $r = [self::$stdin]; - $w = $e = null; - if(($count = stream_select($r, $w, $e, 0, 200000)) === 0){ //nothing changed in 200000 microseconds - return true; - }elseif($count === false){ //stream error - $this->initStdin(); - } - - case self::TYPE_PIPED: - if(($raw = fgets(self::$stdin)) === false){ //broken pipe or EOF - $this->initStdin(); - $this->synchronized(function() : void{ - $this->wait(200000); - }); //prevent CPU waste if it's end of pipe - return true; //loop back round - } - - $line = trim($raw); - break; + $r = [self::$stdin]; + $w = $e = null; + if(($count = stream_select($r, $w, $e, 0, 200000)) === 0){ //nothing changed in 200000 microseconds + return true; + }elseif($count === false){ //stream error + $this->initStdin(); } + if(($raw = fgets(self::$stdin)) === false){ //broken pipe or EOF + $this->initStdin(); + $this->synchronized(function() : void{ + $this->wait(200000); + }); //prevent CPU waste if it's end of pipe + return true; //loop back round + } + + $line = trim($raw); + if($line !== ""){ $this->buffer[] = preg_replace("#\\x1b\\x5b([^\\x1b]*\\x7e|[\\x40-\\x50])#", "", $line); if($this->notifier !== null){