mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-22 12:39:43 +00:00
using stream_select to avoid blocking by fread
This commit is contained in:
parent
7bc464d45e
commit
9e38ff764a
2 changed files with 17 additions and 1 deletions
|
|
@ -277,6 +277,9 @@ class ConsoleAPI{
|
||||||
public static function info($msg){
|
public static function info($msg){
|
||||||
console("[INFO] ".$msg);
|
console("[INFO] ".$msg);
|
||||||
}
|
}
|
||||||
|
public static function notice($msg){
|
||||||
|
console("[NOTICE] ".$msg);
|
||||||
|
}
|
||||||
public static function warn($msg){
|
public static function warn($msg){
|
||||||
console("[WARNING] ".$msg);
|
console("[WARNING] ".$msg);
|
||||||
}
|
}
|
||||||
|
|
@ -309,6 +312,7 @@ class ConsoleLoop extends Thread{
|
||||||
|
|
||||||
while(!$this->stop){
|
while(!$this->stop){
|
||||||
$this->line = $this->readLine();
|
$this->line = $this->readLine();
|
||||||
|
if($this->stop) break;
|
||||||
$this->synchronized(function($t) {
|
$this->synchronized(function($t) {
|
||||||
$this->wait();
|
$this->wait();
|
||||||
$this->line = false;
|
$this->line = false;
|
||||||
|
|
@ -324,6 +328,14 @@ class ConsoleLoop extends Thread{
|
||||||
|
|
||||||
private function readLine(){
|
private function readLine(){
|
||||||
if($this->fp){
|
if($this->fp){
|
||||||
|
do{
|
||||||
|
if($this->stop){
|
||||||
|
ConsoleAPI::notice("Force stopping console thread!");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
$read = [$this->fp];
|
||||||
|
$changed = stream_select($read, $write, $except, 1);
|
||||||
|
}while($changed <= 0);
|
||||||
$line = trim(fgets($this->fp));
|
$line = trim(fgets($this->fp));
|
||||||
}else{
|
}else{
|
||||||
$line = trim(readline(""));
|
$line = trim(readline(""));
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,10 @@ class PluginAPI extends stdClass{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __destruct(){
|
public function __destruct(){
|
||||||
|
if(!isset($this->plugins) || !is_array($this->plugins)){
|
||||||
|
ConsoleAPI::warn("PluginAPI::\$plugins is null (destructor called twice?)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
foreach($this->plugins as $p){
|
foreach($this->plugins as $p){
|
||||||
if(method_exists($p[0], "__destruct")){$p[0]->__destruct();};
|
if(method_exists($p[0], "__destruct")){$p[0]->__destruct();};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue