Assign socket only if it was created

Fixes #149
master
Pavel Djundik 4 years ago
parent cd3624704e
commit 904e547fe4

@ -42,13 +42,14 @@
$this->Port = $Port; $this->Port = $Port;
$this->Address = $Address; $this->Address = $Address;
$this->Socket = @FSockOpen( 'udp://' . $Address, $Port, $ErrNo, $ErrStr, $Timeout ); $Socket = @FSockOpen( 'udp://' . $Address, $Port, $ErrNo, $ErrStr, $Timeout );
if( $ErrNo || $this->Socket === false ) if( $ErrNo || $Socket === false )
{ {
throw new SocketException( 'Could not create socket: ' . $ErrStr, SocketException::COULD_NOT_CREATE_SOCKET ); throw new SocketException( 'Could not create socket: ' . $ErrStr, SocketException::COULD_NOT_CREATE_SOCKET );
} }
$this->Socket = $Socket;
Stream_Set_Timeout( $this->Socket, $Timeout ); Stream_Set_Timeout( $this->Socket, $Timeout );
Stream_Set_Blocking( $this->Socket, true ); Stream_Set_Blocking( $this->Socket, true );
} }

@ -57,13 +57,14 @@
{ {
if( !$this->RconSocket ) if( !$this->RconSocket )
{ {
$this->RconSocket = @FSockOpen( $this->Socket->Address, $this->Socket->Port, $ErrNo, $ErrStr, $this->Socket->Timeout ); $RconSocket = @FSockOpen( $this->Socket->Address, $this->Socket->Port, $ErrNo, $ErrStr, $this->Socket->Timeout );
if( $ErrNo || !$this->RconSocket ) if( $ErrNo || !$RconSocket )
{ {
throw new SocketException( 'Can\'t connect to RCON server: ' . $ErrStr, SocketException::CONNECTION_FAILED ); throw new SocketException( 'Can\'t connect to RCON server: ' . $ErrStr, SocketException::CONNECTION_FAILED );
} }
$this->RconSocket = $RconSocket;
Stream_Set_Timeout( $this->RconSocket, $this->Socket->Timeout ); Stream_Set_Timeout( $this->RconSocket, $this->Socket->Timeout );
Stream_Set_Blocking( $this->RconSocket, true ); Stream_Set_Blocking( $this->RconSocket, true );
} }

Loading…
Cancel
Save