From: Roland Häder Date: Tue, 10 May 2022 19:31:18 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ab8f3b4e3e0cf03175facd95751296f4a30ee88b;p=hub.git Continued: - added more debug lines - $encodedData was a one-usage local variable and can be avoided for more compact and hopefully easier code Signed-off-by: Roland Häder --- 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