mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-11 12:27:51 +00:00
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:
parent
ee868bcccc
commit
1bb2d162ab
@ -116,37 +116,28 @@ 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){
|
$r = [self::$stdin];
|
||||||
/** @noinspection PhpMissingBreakStatementInspection */
|
$w = $e = null;
|
||||||
case self::TYPE_STREAM:
|
if(($count = stream_select($r, $w, $e, 0, 200000)) === 0){ //nothing changed in 200000 microseconds
|
||||||
//stream_select doesn't work on piped streams for some reason
|
return true;
|
||||||
$r = [self::$stdin];
|
}elseif($count === false){ //stream error
|
||||||
$w = $e = null;
|
$this->initStdin();
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 !== ""){
|
if($line !== ""){
|
||||||
$this->buffer[] = preg_replace("#\\x1b\\x5b([^\\x1b]*\\x7e|[\\x40-\\x50])#", "", $line);
|
$this->buffer[] = preg_replace("#\\x1b\\x5b([^\\x1b]*\\x7e|[\\x40-\\x50])#", "", $line);
|
||||||
if($this->notifier !== null){
|
if($this->notifier !== null){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user