From 9b86f70d2b26908bf338b671376c482e837ffdfa Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 3 Dec 2020 09:38:00 +0100 Subject: [PATCH] Continued: - $socketInstance is required in BaseConnectionHelper, so moved the trait loading there - also fixed NULL reference as it might not be set at all times MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../connection/class_BaseConnectionHelper.php | 17 ++++++++++++++--- .../ipv4/class_BaseIpV4ConnectionHelper.php | 2 -- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/application/hub/classes/helper/connection/class_BaseConnectionHelper.php b/application/hub/classes/helper/connection/class_BaseConnectionHelper.php index e3ed55c08..ec409c796 100644 --- a/application/hub/classes/helper/connection/class_BaseConnectionHelper.php +++ b/application/hub/classes/helper/connection/class_BaseConnectionHelper.php @@ -3,6 +3,7 @@ namespace Org\Shipsimu\Hub\Helper\Connection; // Import application-specific stuff +use Org\Shipsimu\Hub\Container\Socket\StorableSocket; use Org\Shipsimu\Hub\Factory\Fragmenter\FragmenterFactory; use Org\Shipsimu\Hub\Factory\Handler\Network\NetworkPackageHandlerFactory; use Org\Shipsimu\Hub\Factory\Network\NetworkPackageFactory; @@ -12,6 +13,7 @@ use Org\Shipsimu\Hub\Helper\BaseHubSystemHelper; use Org\Shipsimu\Hub\Network\Delivery\Deliverable; use Org\Shipsimu\Hub\Network\Package\DeliverablePackage; use Org\Shipsimu\Hub\Network\Package\Delivery\Fragment\Fragmentable; +use Org\Shipsimu\Hub\Traits\Container\Socket\StorableSocketTrait; use Org\Shipsimu\Hub\Traits\Fragmenter\FragmentableTrait; // Import framework stuff @@ -52,6 +54,7 @@ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visit use FragmentableTrait; use OutputStreamTrait; use StateableTrait; + use StorableSocketTrait; // Exception codes const EXCEPTION_UNSUPPORTED_ERROR_HANDLER = 0x9100; @@ -188,10 +191,18 @@ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visit * @return $class Expanded class name */ private function getConnectionClassNameFromSocket () { - // Get recipient address/port + // Default is none /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-CONNECTION-HELPER: CALLED!'); - $recipientAddress = $this->getSocketInstance()->getSocketRecipientAddress(); - $recipientPort = $this->getSocketInstance()->getSocketRecipientPort(); + $recipientAddress = '0.0.0.0'; + $recipientPort = 0; + + // Is a socket instance set? + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-CONNECTION-HELPER: socketInstance[]=%s', gettype($this->getSocketInstance()))); + if ($this->getSocketInstance() instanceof StorableSocket) { + // Get recipient address/port + $recipientAddress = $this->getSocketInstance()->getSocketRecipientAddress(); + $recipientPort = $this->getSocketInstance()->getSocketRecipientPort(); + } // Construct it /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-CONNECTION-HELPER: recipientAddress=%s,recipientPort=%d', $recipientAddress, $recipientPort)); diff --git a/application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php b/application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php index e26b4eb87..51182d0ae 100644 --- a/application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php +++ b/application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php @@ -6,7 +6,6 @@ namespace Org\Shipsimu\Hub\Helper\Connection\Network\IpV4; use Org\Shipsimu\Hub\Factory\State\Peer\PeerStateFactory; use Org\Shipsimu\Hub\Helper\Connection\BaseConnectionHelper; use Org\Shipsimu\Hub\Locator\Node\LocateableNode; -use Org\Shipsimu\Hub\Traits\Container\Socket\StorableSocketTrait; // Import framework stuff use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap; @@ -41,7 +40,6 @@ use \BadMethodCallException; abstract class BaseIpV4ConnectionHelper extends BaseConnectionHelper { // Load traits use HandleableTrait; - use StorableSocketTrait; /** * Name of used protocol -- 2.39.5