mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 04:17:07 +00:00
RCON: properly handle potential errors during socket setup
This commit is contained in:
parent
63b109f23e
commit
619a9892e5
@ -25,6 +25,7 @@ namespace pocketmine\level\format\io\region;
|
||||
|
||||
use pocketmine\level\format\ChunkException;
|
||||
use pocketmine\level\format\io\exception\CorruptedChunkException;
|
||||
use pocketmine\utils\AssumptionFailedError;
|
||||
use pocketmine\utils\Binary;
|
||||
use pocketmine\utils\MainLogger;
|
||||
use function ceil;
|
||||
@ -98,7 +99,9 @@ class RegionLoader{
|
||||
throw new CorruptedRegionException("Region file should be padded to a multiple of 4KiB");
|
||||
}
|
||||
|
||||
$this->filePointer = fopen($this->filePath, "r+b");
|
||||
$filePointer = fopen($this->filePath, "r+b");
|
||||
if($filePointer === false) throw new AssumptionFailedError("fopen() should not fail here");
|
||||
$this->filePointer = $filePointer;
|
||||
stream_set_read_buffer($this->filePointer, 1024 * 16); //16KB
|
||||
stream_set_write_buffer($this->filePointer, 1024 * 16); //16KB
|
||||
if(!$exists){
|
||||
|
@ -75,13 +75,17 @@ class RCON{
|
||||
throw new \InvalidArgumentException("Empty password");
|
||||
}
|
||||
|
||||
$this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
|
||||
$socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
|
||||
if($socket === false){
|
||||
throw new \RuntimeException("Failed to create socket:" . trim(socket_strerror(socket_last_error())));
|
||||
}
|
||||
$this->socket = $socket;
|
||||
|
||||
if(!socket_set_option($this->socket, SOL_SOCKET, SO_REUSEADDR, 1)){
|
||||
throw new \RuntimeException("Unable to set option on socket: " . trim(socket_strerror(socket_last_error())));
|
||||
}
|
||||
|
||||
if($this->socket === false or !@socket_bind($this->socket, $interface, $port) or !@socket_listen($this->socket, 5)){
|
||||
if(!@socket_bind($this->socket, $interface, $port) or !@socket_listen($this->socket, 5)){
|
||||
throw new \RuntimeException(trim(socket_strerror(socket_last_error())));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user