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).
This commit is contained in:
Dylan K. Taylor 2021-03-16 21:42:18 +00:00
parent ee868bcccc
commit 1bb2d162ab
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -116,16 +116,10 @@ class CommandReader extends Thread{
* @return bool if the main execution should continue reading lines * @return bool if the main execution should continue reading lines
*/ */
private function readLine() : bool{ private function readLine() : bool{
$line = "";
if(!is_resource(self::$stdin)){ if(!is_resource(self::$stdin)){
$this->initStdin(); $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]; $r = [self::$stdin];
$w = $e = null; $w = $e = null;
if(($count = stream_select($r, $w, $e, 0, 200000)) === 0){ //nothing changed in 200000 microseconds if(($count = stream_select($r, $w, $e, 0, 200000)) === 0){ //nothing changed in 200000 microseconds
@ -134,7 +128,6 @@ class CommandReader extends Thread{
$this->initStdin(); $this->initStdin();
} }
case self::TYPE_PIPED:
if(($raw = fgets(self::$stdin)) === false){ //broken pipe or EOF if(($raw = fgets(self::$stdin)) === false){ //broken pipe or EOF
$this->initStdin(); $this->initStdin();
$this->synchronized(function() : void{ $this->synchronized(function() : void{
@ -144,8 +137,6 @@ class CommandReader extends Thread{
} }
$line = trim($raw); $line = trim($raw);
break;
}
if($line !== ""){ if($line !== ""){
$this->buffer[] = preg_replace("#\\x1b\\x5b([^\\x1b]*\\x7e|[\\x40-\\x50])#", "", $line); $this->buffer[] = preg_replace("#\\x1b\\x5b([^\\x1b]*\\x7e|[\\x40-\\x50])#", "", $line);