]> git.mxchange.org Git - hub.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Thu, 3 Dec 2020 08:38:00 +0000 (09:38 +0100)
committerRoland Häder <roland@mxchange.org>
Thu, 3 Dec 2020 08:38:00 +0000 (09:38 +0100)
- $socketInstance is required in BaseConnectionHelper, so moved the trait
  loading there
- also fixed NULL reference as it might not be set at all times

Signed-off-by: Roland Häder <roland@mxchange.org>
application/hub/classes/helper/connection/class_BaseConnectionHelper.php
application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php

index e3ed55c089ca36314c4305c7715894e7a38db26b..ec409c7960ae08de978220ba650d20a2ab69c8d7 100644 (file)
@@ -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));
index e26b4eb87122da7a890a9e40ed2efc1a5e86a80c..51182d0ae151aa2d538a937b853bb0be2a588f6b 100644 (file)
@@ -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