Fixed a weird, random, pthreads-caused crash

This commit is contained in:
Shoghi Cervantes Pueyo 2013-04-09 17:21:49 +02:00
parent 533b175b66
commit 79ca735fb0
3 changed files with 25 additions and 3 deletions

View File

@ -33,6 +33,6 @@ require_once(FILE_PATH."/src/dependencies.php");
/***REM_END***/ /***REM_END***/
$server = new ServerAPI(); $server = new ServerAPI();
$server->run(); $server->start();
exit(0); exit(0);

View File

@ -28,14 +28,20 @@ the Free Software Foundation, either version 3 of the License, or
class ServerAPI{ class ServerAPI{
var $restart = false; var $restart = false;
private static $serverRequest = false; private static $serverRequest = false;
private $asyncCalls = array();
private $server; private $server;
private $config; private $config;
private $apiList = array(); private $apiList = array();
private $asyncCnt = 0;
public static function request(){ public static function request(){
return self::$serverRequest; return self::$serverRequest;
} }
public function start(){
return $this->run();
}
public function run(){ public function run(){
$this->load(); $this->load();
return $this->init(); return $this->init();
@ -223,13 +229,29 @@ class ServerAPI{
$this->server->loadEntities(); $this->server->loadEntities();
} }
public function async(callable $callable, $params = array()){
$cnt = $this->asyncCnt++;
$this->asyncCalls[$cnt] = new Async($callable, $params);
return $cnt;
}
public function getAsync($id){
if(!isset($this->asyncCalls[$id])){
return false;
}
$ob = $this->asyncCalls[$id];
$this->asyncCalls[$id] = null;
unset($this->asyncCalls[$id]);
return $ob;
}
public function sendUsage(){ public function sendUsage(){
console("[INTERNAL] Sending usage data...", true, true, 3); console("[INTERNAL] Sending usage data...", true, true, 3);
$plist = ""; $plist = "";
foreach($this->plugin->getList() as $p){ foreach($this->plugin->getList() as $p){
$plist .= str_replace(array(";", ":"), "", $p["name"]).":".str_replace(array(";", ":"), "", $p["version"]).";"; $plist .= str_replace(array(";", ":"), "", $p["name"]).":".str_replace(array(";", ":"), "", $p["version"]).";";
} }
Async::call("Utils::curl_post", array( $this->async("Utils::curl_post", array(
0 => "http://stats.pocketmine.net/usage.php", 0 => "http://stats.pocketmine.net/usage.php",
1 => array( 1 => array(
"serverid" => $this->server->serverID, "serverid" => $this->server->serverID,

View File

@ -35,7 +35,7 @@ define("BIG_ENDIAN", 0x00);
define("LITTLE_ENDIAN", 0x01); define("LITTLE_ENDIAN", 0x01);
define("ENDIANNESS", (pack("d", 1) === "\77\360\0\0\0\0\0\0" ? BIG_ENDIAN:LITTLE_ENDIAN)); define("ENDIANNESS", (pack("d", 1) === "\77\360\0\0\0\0\0\0" ? BIG_ENDIAN:LITTLE_ENDIAN));
class Utils extends Thread{ class Utils{
public static $online = true; public static $online = true;
public function run(){ public function run(){