$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
}
} // 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;