update for pthreads-free raklib

This commit is contained in:
Dylan K. Taylor 2020-03-31 19:41:37 +01:00
parent 37701267f0
commit 64d5320ac9
4 changed files with 83 additions and 8 deletions

View File

@ -0,0 +1,39 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\network\mcpe\raklib;
use raklib\server\ipc\InterThreadChannelReader;
final class PthreadsChannelReader implements InterThreadChannelReader{
/** @var \Threaded */
private $buffer;
public function __construct(\Threaded $buffer){
$this->buffer = $buffer;
}
public function read() : ?string{
return $this->buffer->shift();
}
}

View File

@ -0,0 +1,40 @@
<?php
/*
* RakLib network library
*
*
* This project is not affiliated with Jenkins Software LLC nor RakNet.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*/
declare(strict_types=1);
namespace pocketmine\network\mcpe\raklib;
use pocketmine\snooze\SleeperNotifier;
use raklib\server\ipc\InterThreadChannelWriter;
final class PthreadsChannelWriter implements InterThreadChannelWriter{
/** @var \Threaded */
private $buffer;
/** @var SleeperNotifier|null */
private $notifier;
public function __construct(\Threaded $buffer, ?SleeperNotifier $notifier = null){
$this->buffer = $buffer;
$this->notifier = $notifier;
}
public function write(string $str) : void{
$this->buffer[] = $str;
if($this->notifier !== null){
$this->notifier->wakeupSleeper();
}
}
}

View File

@ -35,8 +35,6 @@ use pocketmine\utils\Utils;
use raklib\protocol\EncapsulatedPacket;
use raklib\protocol\PacketReliability;
use raklib\RakLib;
use raklib\server\ipc\InterThreadChannelReader;
use raklib\server\ipc\InterThreadChannelWriter;
use raklib\server\ipc\RakLibToUserThreadMessageReceiver;
use raklib\server\ipc\UserToRakLibThreadMessageSender;
use raklib\server\ServerEventListener;
@ -104,10 +102,10 @@ class RakLibInterface implements ServerEventListener, AdvancedNetworkInterface{
);
$this->eventReceiver = new RakLibToUserThreadMessageReceiver(
$this,
new InterThreadChannelReader($threadToMainBuffer)
new PthreadsChannelReader($threadToMainBuffer)
);
$this->interface = new UserToRakLibThreadMessageSender(
new InterThreadChannelWriter($mainToThreadBuffer)
new PthreadsChannelWriter($mainToThreadBuffer)
);
}

View File

@ -27,8 +27,6 @@ use pocketmine\snooze\SleeperNotifier;
use pocketmine\thread\Thread;
use raklib\generic\Socket;
use raklib\RakLib;
use raklib\server\ipc\InterThreadChannelReader;
use raklib\server\ipc\InterThreadChannelWriter;
use raklib\server\ipc\RakLibToUserThreadMessageSender;
use raklib\server\ipc\UserToRakLibThreadMessageReceiver;
use raklib\server\SessionManager;
@ -161,8 +159,8 @@ class RakLibServer extends Thread{
$socket,
$this->maxMtuSize,
$this->protocolVersion,
new UserToRakLibThreadMessageReceiver(new InterThreadChannelReader($this->mainToThreadBuffer)),
new RakLibToUserThreadMessageSender(new InterThreadChannelWriter($this->threadToMainBuffer, $this->mainThreadNotifier)),
new UserToRakLibThreadMessageReceiver(new PthreadsChannelReader($this->mainToThreadBuffer)),
new RakLibToUserThreadMessageSender(new PthreadsChannelWriter($this->threadToMainBuffer, $this->mainThreadNotifier)),
new ExceptionTraceCleaner($this->mainPath)
);
$this->synchronized(function() : void{