mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-17 03:08:58 +00:00
Added #1196 async function queuing
Type ID: ASYNC_FUNCTION Params: array("function" => $functionName, "arguments" => array $argumentArray)
This commit is contained in:
parent
13274ebefa
commit
24722e3c9a
@ -228,6 +228,10 @@ class MainServer{
|
|||||||
$d .= Utils::writeShort(strlen($key)).$key . Utils::writeInt(strlen($value)).$value;
|
$d .= Utils::writeShort(strlen($key)).$key . Utils::writeInt(strlen($value)).$value;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case ASYNC_FUNCTION:
|
||||||
|
$params = serialize($data["arguments"]);
|
||||||
|
$d .= Utils::writeShort(strlen($data["function"])).$data["function"] . Utils::writeInt(strlen($params)) . $params;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -256,6 +260,12 @@ class MainServer{
|
|||||||
$data["result"] = substr($this->asyncThread->output, $offset, $len);
|
$data["result"] = substr($this->asyncThread->output, $offset, $len);
|
||||||
$offset += $len;
|
$offset += $len;
|
||||||
break;
|
break;
|
||||||
|
case ASYNC_FUNCTION:
|
||||||
|
$len = Utils::readInt(substr($this->asyncThread->output, $offset, 4));
|
||||||
|
$offset += 4;
|
||||||
|
$data["result"] = unserialize(substr($this->asyncThread->output, $offset, $len));
|
||||||
|
$offset += $len;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
$this->asyncThread->output = substr($this->asyncThread->output, $offset);
|
$this->asyncThread->output = substr($this->asyncThread->output, $offset);
|
||||||
if(isset($this->async[$ID]) and $this->async[$ID] !== null and is_callable($this->async[$ID])){
|
if(isset($this->async[$ID]) and $this->async[$ID] !== null and is_callable($this->async[$ID])){
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
define("ASYNC_CURL_GET", 1);
|
define("ASYNC_CURL_GET", 1);
|
||||||
define("ASYNC_CURL_POST", 2);
|
define("ASYNC_CURL_POST", 2);
|
||||||
|
define("ASYNC_FUNCTION", 3);
|
||||||
|
|
||||||
class StackableArray extends Stackable{
|
class StackableArray extends Stackable{
|
||||||
public function __construct(){
|
public function __construct(){
|
||||||
@ -94,6 +95,12 @@ class AsyncMultipleQueue extends Thread{
|
|||||||
$this->output .= Utils::writeInt($rID).Utils::writeShort(ASYNC_CURL_POST).Utils::writeInt(strlen($res)).$res;
|
$this->output .= Utils::writeInt($rID).Utils::writeShort(ASYNC_CURL_POST).Utils::writeInt(strlen($res)).$res;
|
||||||
$this->unlock();
|
$this->unlock();
|
||||||
break;
|
break;
|
||||||
|
case ASYNC_FUNCTION:
|
||||||
|
$function = $this->get(Utils::readShort($this->get(2), false));
|
||||||
|
$params = unserialize($this->get(Utils::readInt($this->get(4))));
|
||||||
|
$res = serialize(@call_user_func_array($function, $params));
|
||||||
|
$this->output .= Utils::writeInt($rID).Utils::writeShort(ASYNC_FUNCTION).Utils::writeInt(strlen($res)).$res;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
usleep(10000);
|
usleep(10000);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user