* @param $packageHandlerInstance The network package instance we shall set
* @return void
*/
- private final function setPackageHandlerInstance (Deliverable $packageHandlerInstance) {
+ private function setPackageHandlerInstance (Deliverable $packageHandlerInstance) {
$this->packageHandlerInstance = $packageHandlerInstance;
}
$encodedData = $this->getOutputStreamInstance()->streamData($rawData);
// Create data array
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-CONNECTION-HELPER: bufferSize=%d,rawData()=%d, this->socketResource[%s]=%s', $bufferSize, strlen($rawData), gettype($this->getSocketInstance()->getSocketResource()), $this->getSocketInstance()->getSocketResource()));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-CONNECTION-HELPER: bufferSize=%d,rawData()=%d, this->socketResource[%s]=%s', $bufferSize, strlen($rawData), gettype($this->getSocketInstance()->getSocketResource()), $this->getSocketInstance()->getPrintableName()));
$encodedDataArray = [
NetworkPackageHandler::RAW_INDEX_FINAL_HASH => $this->currentFinalHash,
NetworkPackageHandler::RAW_INDEX_ENCODED_DATA => $encodedData,
$time = time();
// This won't loop forever ...
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-IPV4-CONNECTION-HELPER: Trying to connect to %s with socketResource[%s]=%s ...', $this->getSocketInstance()->getSocketRecipientUnl(), gettype($this->getSocketInstance()->getSocketResource()), $this->getSocketInstance()->getSocketResource()));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-IPV4-CONNECTION-HELPER: Trying to connect to %s with socketResource[%s]=%s ...', $this->getSocketInstance()->getSocketRecipientUnl(), gettype($this->getSocketInstance()->getSocketResource()), $this->getSocketInstance()->getPrintableName()));
while (true) {
// Try to connect until it is connected
$isConnected = $this->getSocketInstance()->connectToSocketRecipient();
$socketError = $this->getSocketInstance()->getLastSocketErrorCode();
// Skip any errors which may happen on non-blocking connections
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-IPV4-CONNECTION-HELPER: socketResource=%s,socketError=%d (%s),isConnected=%s', $this->getSocketInstance()->getSocketResource(), $socketError, $this->getSocketInstance()->getLastSocketErrorMessage(), intval($isConnected)));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-IPV4-CONNECTION-HELPER: socketResource=%s,socketError=%d (%s),isConnected=%s', $this->getSocketInstance()->getPrintableName(), $socketError, $this->getSocketInstance()->getLastSocketErrorMessage(), intval($isConnected)));
if ($socketError == SOCKET_EINPROGRESS) {
// "Operation in progress" is common for non-blocking I/O
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-IPV4-CONNECTION-HELPER: socketResource=%s - BREAK!', $this->getSocketInstance()->getSocketResource()));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-IPV4-CONNECTION-HELPER: socketResource=%s - BREAK!', $this->getSocketInstance()->getPrintableName()));
break;
} elseif ($socketError == SOCKET_EALREADY) {
// Calculate passed time
$reached = (time() - $time);
// Now, is that attempt within parameters?
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-IPV4-CONNECTION-HELPER: socketResource=%s,reached=%d,timeout=%d', $this->getSocketInstance()->getSocketResource(), $reached, $timeout));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-IPV4-CONNECTION-HELPER: socketResource=%s,reached=%d,timeout=%d', $this->getSocketInstance()->getPrintableName(), $reached, $timeout));
if ($reached >= $timeout) {
// Didn't work within timeout
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-IPV4-CONNECTION-HELPER: timeout=%d reached, connection attempt failed. - BREAK!', $timeout));
$this->idle(1000);
} elseif ($socketError != 0) {
// Stop on everything else pronto
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-IPV4-CONNECTION-HELPER: socketResource=%s,socketError=%d detected, setting isConnected=FALSE - BREAK!', $this->getSocketInstance()->getSocketResource(), $socketError));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-IPV4-CONNECTION-HELPER: socketResource=%s,socketError=%d detected, setting isConnected=FALSE - BREAK!', $this->getSocketInstance()->getPrintableName(), $socketError));
$isConnected = FALSE;
break;
}
* what is wanted here. This means, that all connections will end with
* isConnected=FALSE here.
*/
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-IPV4-CONNECTION-HELPER: socketResource=%s,socketError=%d,isConnected=%d,hasTimedOut=%d after while() loop.', $this->getSocketInstance()->getSocketResource(), $socketError, intval($isConnected), intval($hasTimedOut)));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-IPV4-CONNECTION-HELPER: socketResource=%s,socketError=%d,isConnected=%d,hasTimedOut=%d after while() loop.', $this->getSocketInstance()->getPrintableName(), $socketError, intval($isConnected), intval($hasTimedOut)));
if (($hasTimedOut === FALSE) && ($socketError == SOCKET_EINPROGRESS)) {
// A "connection in progress" has not timed out. All fine.
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-IPV4-CONNECTION-HELPER: Clearing "operation in progress" as this is for 99.999% chance a non-blocking I/O operation.');
}
// Is the peer connected?
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-IPV4-CONNECTION-HELPER: socketResource=%s,socketError=%d,isConnected=%d,hasTimedOut=%d after while() loop.', $this->getSocketInstance()->getSocketResource(), $socketError, intval($isConnected), intval($hasTimedOut)));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-IPV4-CONNECTION-HELPER: socketResource=%s,socketError=%d,isConnected=%d,hasTimedOut=%d after while() loop.', $this->getSocketInstance()->getPrintableName(), $socketError, intval($isConnected), intval($hasTimedOut)));
if ($isConnected === TRUE) {
// Connection is fully established here, so change the state.
PeerStateFactory::createPeerStateInstanceByName('connected', $this);
throw new InvalidConnectionTypeException(array($this, $connectionType), self::EXCEPTION_INVALID_CONNECTION_TYPE);
} elseif ((!empty($connectionType)) && ($socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE] !== $connectionType)) {
// Skip unwanted sockets
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DEFAULT-PEER-POOL: Skipping unwanted socket %s of type %s/%s ...', $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketResource(), $socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE], $connectionType));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DEFAULT-PEER-POOL: Skipping unwanted socket %s of type %s/%s ...', $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getPrintableName(), $socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE], $connectionType));
continue;
}
$peerPort = 0;
// Try to get the "peer"'s name
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DEFAULT-PEER-POOL: socketInstance->socketResource=%s,socketInstance->socketProtocol=%s,socketArray[%s]=%s', $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketResource(), $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketProtocol(), Poolable::SOCKET_ARRAY_CONN_TYPE, $socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE]));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DEFAULT-PEER-POOL: socketInstance->socketResource=%s,socketInstance->socketProtocol=%s,socketArray[%s]=%s', $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getPrintableName(), $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketProtocol(), Poolable::SOCKET_ARRAY_CONN_TYPE, $socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE]));
if (!$socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->determineSocketPeerName($peerAddress, $peerPort)) {
// Handle the socket error with given package data
$socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->handleSocketError(__METHOD__, __LINE__);
$socketInstance = $socketArray[Poolable::SOCKET_ARRAY_INSTANCE];
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DEFAULT-PEER-POOL: peerAddress=%s matches with recipient IP address. Taking socketResource=%s,type=%s', $peerAddress, $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketResource(), $socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE]));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DEFAULT-PEER-POOL: peerAddress=%s matches with recipient IP address. Taking socketResource=%s,type=%s', $peerAddress, $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getPrintableName(), $socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE]));
break;
}
}