From ab8f3b4e3e0cf03175facd95751296f4a30ee88b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 10 May 2022 21:31:18 +0200 Subject: [PATCH] Continued: - added more debug lines - $encodedData was a one-usage local variable and can be avoided for more compact and hopefully easier code MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../container/socket/class_SocketContainer.php | 2 +- .../helper/connection/class_BaseConnectionHelper.php | 11 +++++------ .../classes/info/connection/class_ConnectionInfo.php | 3 ++- .../hub/classes/listener/class_BaseListener.php | 7 ++++++- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/application/hub/classes/container/socket/class_SocketContainer.php b/application/hub/classes/container/socket/class_SocketContainer.php index e65cb7b2b..fca7dd3a7 100644 --- a/application/hub/classes/container/socket/class_SocketContainer.php +++ b/application/hub/classes/container/socket/class_SocketContainer.php @@ -914,7 +914,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita $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 diff --git a/application/hub/classes/helper/connection/class_BaseConnectionHelper.php b/application/hub/classes/helper/connection/class_BaseConnectionHelper.php index d78d6ec0b..6350345a2 100644 --- a/application/hub/classes/helper/connection/class_BaseConnectionHelper.php +++ b/application/hub/classes/helper/connection/class_BaseConnectionHelper.php @@ -327,6 +327,7 @@ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visit } // 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 @@ -334,6 +335,7 @@ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visit $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))); @@ -363,14 +365,10 @@ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visit $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, @@ -378,6 +376,7 @@ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visit ]; // 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 diff --git a/application/hub/classes/info/connection/class_ConnectionInfo.php b/application/hub/classes/info/connection/class_ConnectionInfo.php index 533185861..4b6557bfb 100644 --- a/application/hub/classes/info/connection/class_ConnectionInfo.php +++ b/application/hub/classes/info/connection/class_ConnectionInfo.php @@ -205,13 +205,14 @@ class ConnectionInfo extends BaseInfo implements ShareableInfo, Registerable { $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); diff --git a/application/hub/classes/listener/class_BaseListener.php b/application/hub/classes/listener/class_BaseListener.php index 3a7ffd8a5..d73588837 100644 --- a/application/hub/classes/listener/class_BaseListener.php +++ b/application/hub/classes/listener/class_BaseListener.php @@ -248,7 +248,7 @@ abstract class BaseListener extends BaseHubSystem implements Visitable { $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 @@ -402,6 +402,7 @@ abstract class BaseListener extends BaseHubSystem implements Visitable { } // 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? @@ -412,6 +413,7 @@ abstract class BaseListener extends BaseHubSystem implements Visitable { } // 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 @@ -426,13 +428,16 @@ abstract class BaseListener extends BaseHubSystem implements Visitable { // 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 -- 2.39.5