Skip to content

Commit

Permalink
reopen stdin if broken and close stdin on shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
robske110 committed Nov 15, 2016
1 parent d29e964 commit 7fa9f60
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/pocketmine/command/CommandReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,18 @@ public function shutdown(){
$this->shutdown = true;
}

private function initStdin(){
global $stdin;
$stdin = fopen("php://stdin", "r");
stream_set_blocking($stdin, 0);
}

private function readLine(){
if(!$this->readline){
global $stdin;

if(!is_resource($stdin)){
return "";
$this->initStdin();
}

return trim(fgets($stdin));
Expand Down Expand Up @@ -74,9 +80,7 @@ public function getLine(){

public function run(){
if(!$this->readline){
global $stdin;
$stdin = fopen("php://stdin", "r");
stream_set_blocking($stdin, 0);
$this->initStdin();
}

$lastLine = microtime(true);
Expand All @@ -91,6 +95,8 @@ public function run(){

$lastLine = microtime(true);
}
global $stdin;
fclose($stdin);
}

public function getThreadName(){
Expand Down

0 comments on commit 7fa9f60

Please sign in to comment.