From 7eaf6fa0864e8494328116b8ff9fcc4b3ceb48cf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 30 May 2017 21:27:00 +0200 Subject: [PATCH] Fixes: - these iterators must be stored separately, else file/tcp/udp socket instances getting entirely mixed up - also better splitted configuration entries, some more don't really hurt - better debug message (info was not really correct) 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 +- .../factories/socket/class_SocketFactory.php | 11 +++++++---- .../registry/socket/class_SocketRegistry.php | 14 +++++++------- application/hub/config.php | 10 ++++++++-- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/application/hub/classes/container/socket/class_SocketContainer.php b/application/hub/classes/container/socket/class_SocketContainer.php index 688ea4cbb..5eabaaaad 100644 --- a/application/hub/classes/container/socket/class_SocketContainer.php +++ b/application/hub/classes/container/socket/class_SocketContainer.php @@ -1411,7 +1411,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita */ private function setSocketOption ($level, $optionName, $optionValue) { // Trace message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: level=%s,optionName=%s,optionValue[%s]=%s - CALLED!', strtoupper($this->getSocketProtocol()), $level, $optionName, gettype($optionValue), $optionValue)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: level=%s,optionName=%s,optionValue[%s]=%s - CALLED!', strtoupper($this->getSocketProtocol()), $level, $optionName, gettype($optionValue), implode(',', $optionValue))); // Should be valid socket if (!$this->isValidSocket()) { diff --git a/application/hub/classes/factories/socket/class_SocketFactory.php b/application/hub/classes/factories/socket/class_SocketFactory.php index beb2b2003..1fcf974b7 100644 --- a/application/hub/classes/factories/socket/class_SocketFactory.php +++ b/application/hub/classes/factories/socket/class_SocketFactory.php @@ -403,16 +403,19 @@ class SocketFactory extends ObjectFactory { // Trace message /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: poolInstance=%s,socketInstance.socketResource=%s - CALLED!', $poolInstance->__toString(), $socketInstance->getSocketResource())); + // Get socket protocol + $socketProtocol = $socketInstance->getSocketProtocol(); + // Is the an iterator instance? - if (!Registry::getRegistry()->instanceExists('pool_iterator')) { + if (!Registry::getRegistry()->instanceExists('pool_iterator_' . $socketProtocol)) { // Create iterator instance - $iteratorInstance = $poolInstance->createListIteratorInstance('pool'); + $iteratorInstance = $poolInstance->createListIteratorInstance($socketProtocol . '_pool'); // Now store it in registry Registry::getRegistry()->addInstance('pool_iterator', $iteratorInstance); } else { // Get iterator from registry - $iteratorInstance = Registry::getRegistry()->getInstance('pool_iterator'); + $iteratorInstance = Registry::getRegistry()->getInstance('pool_iterator_' . $socketProtocol); } // Is it valid? @@ -479,7 +482,7 @@ class SocketFactory extends ObjectFactory { } // END - if // Set timeout to configured seconds - if (!$socketinstance->setSocketTimeoutOptions()) { + if (!$socketInstance->setSocketTimeoutOptions()) { // Handle this socket error with a faked recipientData array $socketInstance->handleSocketEror(__METHOD__, __LINE__, array('0.0.0.0', '0')); } // END - if diff --git a/application/hub/classes/registry/socket/class_SocketRegistry.php b/application/hub/classes/registry/socket/class_SocketRegistry.php index dcc614694..4657192dd 100644 --- a/application/hub/classes/registry/socket/class_SocketRegistry.php +++ b/application/hub/classes/registry/socket/class_SocketRegistry.php @@ -137,7 +137,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke */ private function isInfoRegistered (ShareableInfo $infoInstance) { // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY:info=' . $infoInstance->getProtocolName() . ' - CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: protocolName=' . $infoInstance->getProtocolName() . ' - CALLED!'); // Get the key $key = $this->getRegistryKeyFromInfo($infoInstance); @@ -146,7 +146,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke $isRegistered = $this->instanceExists($key); // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY:info=' . $infoInstance->getProtocolName() . ',isRegistered=' . intval($isRegistered) . ' - EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: protocolName=' . $infoInstance->getProtocolName() . ',isRegistered=' . intval($isRegistered) . ' - EXIT!'); // Return result return $isRegistered; @@ -162,7 +162,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke */ public function isSocketRegistered (ShareableInfo $infoInstance, StorableSocket $socketInstance) { // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY:info=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketInstance->getSocketResource()) . ']=' . $socketInstance->getSocketResource() . ' - CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: protocolName=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketInstance->getSocketResource()) . ']=' . $socketInstance->getSocketResource() . ' - CALLED!'); // Default is not registered $isRegistered = FALSE; @@ -173,7 +173,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke $key = $this->getRegistryKeyFromInfo($infoInstance); // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: this=' . $this->__toString() . ',info=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketInstance->getSocketResource()) . ']=' . $socketInstance->getSocketResource() . ',key=' . $key . ' - Trying to get instance ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: this=' . $this->__toString() . ',protocolName=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketInstance->getSocketResource()) . ']=' . $socketInstance->getSocketResource() . ',key=' . $key . ' - Trying to get instance ...'); // Get the registry $registryInstance = $this->getInstance($key); @@ -182,7 +182,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke $socketKey = $this->getSubRegistryKey($infoInstance); // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: this=' . $this->__toString() . ',info=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketInstance->getSocketResource()) . ']=' . $socketInstance->getSocketResource() . ',key=' . $key . ',socketKey=' . $socketKey . ' - Checking existence ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: this=' . $this->__toString() . ',protocolName=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketInstance->getSocketResource()) . ']=' . $socketInstance->getSocketResource() . ',key=' . $key . ',socketKey=' . $socketKey . ' - Checking existence ...'); // Is it there? if ($registryInstance->instanceExists($socketKey)) { @@ -201,7 +201,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke } // END - if // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY:info=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketInstance->getSocketResource()) . ']=' . $socketInstance->getSocketResource() . ',isRegistered=' . intval($isRegistered) . ' - EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: protocolName=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketInstance->getSocketResource()) . ']=' . $socketInstance->getSocketResource() . ',isRegistered=' . intval($isRegistered) . ' - EXIT!'); // Return the result return $isRegistered; @@ -218,7 +218,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke */ public function registerSocketInstance (ShareableInfo $infoInstance, StorableSocket $socketInstance, array $packageData = array()) { // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY:info=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketInstance->getSocketResource()) . ']=' . $socketInstance->getSocketResource() . ' - CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: protocolName=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketInstance->getSocketResource()) . ']=' . $socketInstance->getSocketResource() . ' - CALLED!'); // Is the socket already registered? if ($this->isSocketRegistered($infoInstance, $socketInstance)) { diff --git a/application/hub/config.php b/application/hub/config.php index ad4c2a7e2..0a9b48f61 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -102,8 +102,14 @@ $cfg->setConfigEntry('application_pool_class', 'Hub\Pool\Peer\DefaultPeerPool'); // CFG: POOL-ENTRIES-LIST-CLASS $cfg->setConfigEntry('pool_entries_list_class', 'Hub\Lists\Pool\PoolEntriesList'); -// CFG: POOL-ITERATOR-CLASS -$cfg->setConfigEntry('pool_iterator_class', 'CoreFramework\Iterator\DefaultIterator'); +// CFG: FILE-POOL-ITERATOR-CLASS +$cfg->setConfigEntry('file_pool_iterator_class', 'CoreFramework\Iterator\DefaultIterator'); + +// CFG: TCP-POOL-ITERATOR-CLASS +$cfg->setConfigEntry('tcp_pool_iterator_class', 'CoreFramework\Iterator\DefaultIterator'); + +// CFG: UDP-POOL-ITERATOR-CLASS +$cfg->setConfigEntry('udp_pool_iterator_class', 'CoreFramework\Iterator\DefaultIterator'); // CFG: SHUTDOWN-POOL-ITERATOR-CLASS $cfg->setConfigEntry('shutdown_pool_iterator_class', 'ShutdownPoolIterator'); -- 2.39.5