*/ protected NonThreadSafeValue $address; /** * @phpstan-param ThreadSafeArray $mainToThreadBuffer * @phpstan-param ThreadSafeArray $threadToMainBuffer */ public function __construct( protected ThreadSafeLogger $logger, protected ThreadSafeArray $mainToThreadBuffer, protected ThreadSafeArray $threadToMainBuffer, InternetAddress $address, protected int $serverId, protected int $maxMtuSize, protected int $protocolVersion, protected SleeperHandlerEntry $sleeperEntry ){ $this->mainPath = \pocketmine\PATH; $this->address = new NonThreadSafeValue($address); } public function startAndWait(int $options = NativeThread::INHERIT_NONE) : void{ $this->start($options); $this->synchronized(function() : void{ while(!$this->ready && $this->getCrashInfo() === null){ $this->wait(); } $crashInfo = $this->getCrashInfo(); if($crashInfo !== null){ if($crashInfo->getType() === SocketException::class){ throw new SocketException($crashInfo->getMessage()); } throw new ThreadCrashException("RakLib failed to start", $crashInfo); } }); } protected function onRun() : void{ gc_enable(); ini_set("display_errors", '1'); ini_set("display_startup_errors", '1'); \GlobalLogger::set($this->logger); $socket = new ServerSocket($this->address->deserialize()); $manager = new Server( $this->serverId, $this->logger, $socket, $this->maxMtuSize, new SimpleProtocolAcceptor($this->protocolVersion), new UserToRakLibThreadMessageReceiver(new PthreadsChannelReader($this->mainToThreadBuffer)), new RakLibToUserThreadMessageSender(new SnoozeAwarePthreadsChannelWriter($this->threadToMainBuffer, $this->sleeperEntry->createNotifier())), new ExceptionTraceCleaner($this->mainPath), recvMaxSplitParts: 512 ); $this->synchronized(function() : void{ $this->ready = true; $this->notify(); }); while(!$this->isKilled){ $manager->tickProcessor(); } $manager->waitShutdown(); } public function getThreadName() : string{ return "RakLib"; } }