mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-06 11:57:10 +00:00
RCON: set SO_REUSEADDR to fix RCON start failure after restart (#3357)
This commit is contained in:
parent
f84abcd1fe
commit
310de5a2b2
@ -41,14 +41,17 @@ use function socket_getsockname;
|
||||
use function socket_last_error;
|
||||
use function socket_listen;
|
||||
use function socket_set_block;
|
||||
use function socket_set_option;
|
||||
use function socket_strerror;
|
||||
use function socket_write;
|
||||
use function trim;
|
||||
use const AF_INET;
|
||||
use const AF_UNIX;
|
||||
use const SO_REUSEADDR;
|
||||
use const SOCK_STREAM;
|
||||
use const SOCKET_ENOPROTOOPT;
|
||||
use const SOCKET_EPROTONOSUPPORT;
|
||||
use const SOL_SOCKET;
|
||||
use const SOL_TCP;
|
||||
|
||||
class RCON{
|
||||
@ -74,6 +77,10 @@ class RCON{
|
||||
|
||||
$this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
|
||||
|
||||
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)){
|
||||
throw new \RuntimeException(trim(socket_strerror(socket_last_error())));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user