$listenerInstance = $infoInstance->getListenerInstance();
$helperInstance = $infoInstance->getHelperInstance();
- // Is there a listener instance set?
+ // Is there a listener or a connection helper instance set?
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: listenerInstance[]=%s,helperInstance[]=%s', strtoupper($this->getSocketProtocol()), gettype($listenerInstance), gettype($helperInstance)));
if ($listenerInstance instanceof Listenable) {
// Set it here for later usage
}
// Reset serial number
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-CONNECTION-HELPER: Resetting serial number for this->currentFinalHash=%s ...', $this->currentFinalHash));
$this->getFragmenterInstance()->resetSerialNumber($this->currentFinalHash);
// Init variables
$dataStream = ' ';
// Fill sending buffer with data
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-CONNECTION-HELPER: while(true) loop - START!');
while (TRUE) {
// Convert the package data array to a raw data stream
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-CONNECTION-HELPER: dataStream()=%d - BEFORE!', strlen($dataStream)));
$bufferSize = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($this->getProtocolName() . '_buffer_length');
// Encode the raw data with our output-stream
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-CONNECTION-HELPER: bufferSize=%d', $bufferSize));
- $encodedData = $this->getOutputStreamInstance()->streamData($rawData);
-
- // Init array
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-CONNECTION-HELPER: socketResource[%s]=%s', gettype($this->getSocketInstance()->getSocketResource()), $this->getSocketInstance()->getSocketResource()));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-CONNECTION-HELPER: bufferSize=%d, socketResource[%s]=%s', $bufferSize, gettype($this->getSocketInstance()->getSocketResource()), $this->getSocketInstance()->getSocketResource()));
$encodedDataArray = [
NetworkPackageHandler::RAW_INDEX_FINAL_HASH => $this->currentFinalHash,
- NetworkPackageHandler::RAW_INDEX_ENCODED_DATA => $encodedData,
+ NetworkPackageHandler::RAW_INDEX_ENCODED_DATA => $this->getOutputStreamInstance()->streamData($rawData),
NetworkPackageHandler::RAW_INDEX_SENT_BYTES => 0,
NetworkPackageHandler::RAW_INDEX_SOCKET_INSTANCE => $this->getSocketInstance(),
NetworkPackageHandler::RAW_INDEX_BUFFER_SIZE => $bufferSize,
];
// Push raw data to the package's outgoing stack
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-CONNECTION-HELPER: Pushing %d large array on stack %s ...', count($encodedDataArray), NetworkPackageHandler::STACKER_NAME_OUTGOING_STREAM));
$this->getPackageHandlerInstance()->getStackInstance()->pushNamed(NetworkPackageHandler::STACKER_NAME_OUTGOING_STREAM, $encodedDataArray);
// Trace message
$socketPort = 0;
// Get peer name
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-INFO: Calling socketInstance->determineSocketPeerName(%s,%d) ...', $socketAddress, $socketPort));
if (!$socketInstance->determineSocketPeerName($socketAddress, $socketPort)) {
// Did not work
throw new InvalidSocketException(array($this, $socketInstance->getSocketResource()), self::EXCEPTION_INVALID_SOCKET);
}
// Fill the generic array with several data from the listener:
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-INFO: socketAddress=%s,socketPort=%d', $socketAddress, $socketPort));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-INFO: Setting socketInstance->socketProtocol=%s,socketAddress=%s,socketPort=%d', $socketInstance->getSocketProtocol(), $socketAddress, $socketPort));
$this->setProtocolName($socketInstance->getSocketProtocol());
$this->setGenericArrayElement('connection', 'dummy', 'dummy', LocateableNode::UNL_PART_ADDRESS , $socketAddress);
$this->setGenericArrayElement('connection', 'dummy', 'dummy', LocateableNode::UNL_PART_PORT , $socketPort);
$infoInstance->fillWithListenerInformation($this);
// Register the socket
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-LISTENER: Registering socketInstance->socketResource=%s,socketType=%s', strtoupper($this->getProtocolName()), $socketInstance->getSocketResource(), $socketInstance->getSocketType()));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-LISTENER: Registering socketInstance->socketResource=%s,socketType=%s ...', strtoupper($this->getProtocolName()), $socketInstance->getSocketResource(), $socketInstance->getSocketType()));
$this->getRegistryInstance()->registerSocketInstance($infoInstance, $socketInstance);
// And set it here
}
// Get a connection info instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-LISTENER: Creating infoInstance for connection type %s ...', strtoupper($this->getProtocolName()), StorableSocket::CONNECTION_TYPE_INCOMING));
$infoInstance = ConnectionInfoFactory::createConnectionInfoInstance($this->getProtocolName(), StorableSocket::CONNECTION_TYPE_INCOMING);
// Is the instance set?
}
// Will the info instance with listener data
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-LISTENER: Calling infoInstance->fillWithSocketPeerInformation(%s) ...', strtoupper($this->getProtocolName()), $socketInstance->__toString()));
$infoInstance->fillWithSocketPeerInformation($socketInstance);
// Init peer address/port
// Set all required data
//* DEBUG-DIE: */ $infoInstance->debugInstance();
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-LISTENER: peerAddress=%s,peerPort=%d', strtoupper($this->getProtocolName()), $peerAddress, $peerPort));
$socketInstance->setSenderAddress($peerAddress);
$socketInstance->setSenderPort($peerPort);
// Register the socket with the registry and with the faked array
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-LISTENER: Registering socketInstance->socketResource=%s,socketType=%s ...', strtoupper($this->getProtocolName()), $socketInstance->getSocketResource(), $socketInstance->getSocketType()));
$this->getRegistryInstance()->registerSocketInstance($infoInstance, $socketInstance);
// Invoke private method
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-LISTENER: Calling this->handleIncomingSocket(%s) ...', strtoupper($this->getProtocolName()), $socketInstance->__toString()));
$this->handleIncomingSocket($socketInstance);
// Trace message