]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/discovery/socket/class_PackageSocketDiscovery.php
Continued on development of 'hub' project with many refactorings/addings:
[hub.git] / application / hub / main / discovery / socket / class_PackageSocketDiscovery.php
index f061c1791b435cc1bc45d83ed78ffaf7c320d284..d08dbb3f232352d31828ee1c8256e4b040f60620 100644 (file)
@@ -113,7 +113,7 @@ class PackageSocketDiscovery extends BaseHubDiscovery implements DiscoverableSoc
                $socketResource = $listenerInstance->getPoolInstance()->getSocketFromPackageData($packageData);
 
                // Is it false, the recipient isn't known to us and we have no connection to it
-               if ((!is_resource($socketResource)) || (socket_last_error($socketResource) > 0)) {
+               if (($socketResource === false) || (!is_resource($socketResource)) || (socket_last_error($socketResource) > 0)) {
                        // Try to create a new socket resource
                        try {
                                // Possibly noisy debug message
@@ -129,14 +129,23 @@ class PackageSocketDiscovery extends BaseHubDiscovery implements DiscoverableSoc
                        }
                } // END - if
 
-               // Get the helper instance from registry
-               $helperInstance = Registry::getRegistry()->getInstance('connection');
+               // Try to resolve the socket resource
+               try {
+                       // Get the helper instance from registry
+                       $helperInstance = Registry::getRegistry()->getInstance('connection');
 
-               // Possibly noisy debug message
-               /* NOISY-DEBUG: */ $this->debugOutput('SOCKET-DISCOVERY: Going to resolve state by given package data ...');
+                       // Possibly noisy debug message
+                       /* NOISY-DEBUG: */ $this->debugOutput('SOCKET-DISCOVERY: Going to resolve socket from peer state and given package data ...');
 
-               // Resolve the peer's state (but ignore return value)
-               PeerStateResolver::resolveStateByPackage($helperInstance, $packageData, $socketResource);
+                       // Resolve the peer's state (but ignore return value)
+                       PeerStateResolver::resolveStateByPackage($helperInstance, $packageData, $socketResource);
+               } catch (InvalidSocketException $e) {
+                       // This cannot be fixed, so log it away
+                       $this->debugOutput('SOCKET-DISCOVERY: Cannot discover socket resource for recipient ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ': ' . $e->getMessage());
+
+                       // Make any failed attempts to 'false'
+                       $socketResource = false;
+               }
 
                // And return it
                return $socketResource;