X-Git-Url: https://git.mxchange.org/?p=hub.git;a=blobdiff_plain;f=application%2Fhub%2Fclasses%2Fhelper%2Fconnection%2Fipv4%2Fclass_BaseIpV4ConnectionHelper.php;h=f1dfa8305cac5a90949a5e56e31f7ab40afe46aa;hp=ba7e7393ba27c70425a87e4bb17478d49ef48585;hb=f6368b592b8d4082f856002f6550f37bcfeeea83;hpb=7bfa50d2cc126904f5ed1573ea72c3887abdfcfe diff --git a/application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php b/application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php index ba7e7393b..f1dfa8305 100644 --- a/application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php +++ b/application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php @@ -121,6 +121,7 @@ class BaseIpV4ConnectionHelper extends BaseConnectionHelper { self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Trying to connect to ' . $unlData[UniversalNodeLocator::UNL_PART_ADDRESS] . ':' . $unlData[UniversalNodeLocator::UNL_PART_PORT] . ' with socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' ...'); // Get current time + $hasTimedOut = FALSE; $time = time(); // Try to connect until it is connected @@ -128,6 +129,9 @@ class BaseIpV4ConnectionHelper extends BaseConnectionHelper { // Get last socket error $socketError = socket_last_error($socketResource); + // Log error code and status + /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: socketError=' . $socketError . ',isConnected=' . intval($isConnected)); + // Skip any errors which may happen on non-blocking connections if (($socketError == SOCKET_EINPROGRESS) || ($socketError == SOCKET_EALREADY)) { // Now, is that attempt within parameters? @@ -137,6 +141,7 @@ class BaseIpV4ConnectionHelper extends BaseConnectionHelper { // Didn't work within timeout $isConnected = FALSE; + $hasTimedOut = TRUE; break; } // END - if @@ -152,11 +157,25 @@ class BaseIpV4ConnectionHelper extends BaseConnectionHelper { } } // END - while + /* + * All IPv4-based connections are non-blocking used by this program or + * else the PHP process will "hang" until a peer connects which is not + * what is wanted here. This means, that all connections will end with + * isConnected=FALSE here. + */ + if (($hasTimedOut === FALSE) && ($socketError == SOCKET_EINPROGRESS)) { + // A "connection in progress" has not timed out. All fine. + $isConnected = TRUE; + + // Clear error + socket_clear_error($socketResource); + } // END - if + // Log error code - /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: socketError=' . $socketError . ',isConnected=' . intval($isConnected) . ' after while() loop.'); + /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: socketError=' . $socketError . ',isConnected=' . intval($isConnected) . ',hasTimedOut=' . intval($hasTimedOut) . ' after while() loop.'); // Is the peer connected? - if ($isConnected === TRUE) { + if (($isConnected === TRUE) || (($socketError == SOCKET_EINPROGRESS) && ($hasTimedOut === FALSE))) { // Connection is fully established here, so change the state. PeerStateFactory::createPeerStateInstanceByName('connected', $this); } else {