mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-30 15:19:56 +00:00
Network: clean up ticking handling, RakLib only processes on Snooze notification
This commit is contained in:
parent
7560880168
commit
e43496e7e4
@ -2537,7 +2537,7 @@ class Server{
|
|||||||
++$this->tickCounter;
|
++$this->tickCounter;
|
||||||
|
|
||||||
Timings::$connectionTimer->startTiming();
|
Timings::$connectionTimer->startTiming();
|
||||||
$this->network->processInterfaces();
|
$this->network->tickInterfaces();
|
||||||
Timings::$connectionTimer->stopTiming();
|
Timings::$connectionTimer->stopTiming();
|
||||||
|
|
||||||
Timings::$schedulerTimer->startTiming();
|
Timings::$schedulerTimer->startTiming();
|
||||||
|
@ -80,16 +80,11 @@ class Network{
|
|||||||
return $this->interfaces;
|
return $this->interfaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function processInterfaces() : void{
|
public function tickInterfaces() : void{
|
||||||
foreach($this->interfaces as $interface){
|
foreach($this->interfaces as $interface){
|
||||||
$this->processInterface($interface);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function processInterface(NetworkInterface $interface) : void{
|
|
||||||
try{
|
try{
|
||||||
$interface->process();
|
$interface->tick();
|
||||||
}catch(\Throwable $e){
|
}catch(\Exception $e){
|
||||||
$logger = $this->server->getLogger();
|
$logger = $this->server->getLogger();
|
||||||
if(\pocketmine\DEBUG > 1){
|
if(\pocketmine\DEBUG > 1){
|
||||||
$logger->logException($e);
|
$logger->logException($e);
|
||||||
@ -102,6 +97,7 @@ class Network{
|
|||||||
$logger->critical($this->server->getLanguage()->translateString("pocketmine.server.networkError", [get_class($interface), $e->getMessage()]));
|
$logger->critical($this->server->getLanguage()->translateString("pocketmine.server.networkError", [get_class($interface), $e->getMessage()]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param NetworkInterface $interface
|
* @param NetworkInterface $interface
|
||||||
|
@ -63,7 +63,7 @@ interface NetworkInterface{
|
|||||||
/**
|
/**
|
||||||
* Called every tick to process events on the interface.
|
* Called every tick to process events on the interface.
|
||||||
*/
|
*/
|
||||||
public function process() : void;
|
public function tick() : void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gracefully shuts down the network interface.
|
* Gracefully shuts down the network interface.
|
||||||
|
@ -71,7 +71,8 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{
|
|||||||
|
|
||||||
$this->sleeper = new SleeperNotifier();
|
$this->sleeper = new SleeperNotifier();
|
||||||
$server->getTickSleeper()->addNotifier($this->sleeper, function() : void{
|
$server->getTickSleeper()->addNotifier($this->sleeper, function() : void{
|
||||||
$this->server->getNetwork()->processInterface($this);
|
//this should not throw any exception. If it does, this should crash the server since it's a fault condition.
|
||||||
|
while($this->interface->handlePacket());
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->rakLib = new RakLibServer(
|
$this->rakLib = new RakLibServer(
|
||||||
@ -93,9 +94,7 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{
|
|||||||
$this->network = $network;
|
$this->network = $network;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function process() : void{
|
public function tick() : void{
|
||||||
while($this->interface->handlePacket()){}
|
|
||||||
|
|
||||||
if(!$this->rakLib->isRunning() and !$this->rakLib->isShutdown()){
|
if(!$this->rakLib->isRunning() and !$this->rakLib->isShutdown()){
|
||||||
throw new \Exception("RakLib Thread crashed");
|
throw new \Exception("RakLib Thread crashed");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user