]> git.mxchange.org Git - hub.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Tue, 10 May 2022 13:56:32 +0000 (15:56 +0200)
committerRoland Häder <roland@mxchange.org>
Tue, 10 May 2022 13:56:32 +0000 (15:56 +0200)
- renamed getSubRegistryKey() -> generateSubRegistryKeyFromInfoInstance() as
  this is not a getter
- also included connection type (e.g. 'server') into sub-registry key
- more debug lines added
- removed superflous $peerSuffix parameter as the ':0' may cause confusion

Signed-off-by: Roland Häder <roland@mxchange.org>
application/hub/classes/listener/class_BaseListener.php
application/hub/classes/listener/tcp/class_TcpListener.php
application/hub/classes/listener/udp/class_UdpListener.php
application/hub/classes/registry/socket/class_SocketRegistry.php

index d0b51d437aef574ab49083dda1ae36e22c9b51d3..3a7ffd8a51d905f5fe9c04171ded53b7abf21348 100644 (file)
@@ -379,13 +379,12 @@ abstract class BaseListener extends BaseHubSystem implements Visitable {
        /**
         * "Listens" for incoming network packages
         *
-        * @param       $peerSuffix             Suffix for peer name (e.g. :0 for TCP(/UDP?) connections)
         * @return      void
         * @throws      LogicException  If no info instance can be created
         */
-       protected function doListenSocketSelect (string $peerSuffix) {
+       protected function doListenSocketSelect () {
                // Validate parameter and socket instance
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-LISTENER: peerSuffix=%s - CALLED!', strtoupper($this->getProtocolName()), $peerSuffix));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-LISTENER: CALLED!', strtoupper($this->getProtocolName())));
                if(!$this->getSocketInstance()->isValidSocket()) {
                        // Invalid socket
                        throw new LogicException(sprintf('this->socketInstance->socketResource=%s is not valid', $this->getSocketInstance()->getSocketResource()));
@@ -427,7 +426,7 @@ abstract class BaseListener extends BaseHubSystem implements Visitable {
 
                // Set all required data
                //* DEBUG-DIE: */ $infoInstance->debugInstance();
-               $socketInstance->setSenderAddress($peerAddress . $peerSuffix);
+               $socketInstance->setSenderAddress($peerAddress);
                $socketInstance->setSenderPort($peerPort);
 
                // Register the socket with the registry and with the faked array
index 44cb6575ede1fe7a04e0db5a54bb1b6b73e3ff13..514612d0887504ca29a11a4a46ce96979d75fd4e 100644 (file)
@@ -105,10 +105,10 @@ class TcpListener extends BaseListener implements Listenable {
         */
        public function doListen () {
                // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-LISTENER: Calling this->doListenSocketSelect(:0) ... - CALLED!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-LISTENER: Calling this->doListenSocketSelect() ... - CALLED!');
 
                // Call super method
-               $this->doListenSocketSelect(':0');
+               $this->doListenSocketSelect();
 
                // Trace message
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-LISTENER: EXIT!');
index d22f4433964d98b8036115c7442d80babd0818c1..79b2f662bf79f41466e1c3b17f47356b524d342e 100644 (file)
@@ -107,10 +107,10 @@ class UdpListener extends BaseListener implements Listenable {
         */
        public function doListen () {
                // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UDP-LISTENER: Calling this->doListenSocketSelect(:0) ... - CALLED!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UDP-LISTENER: Calling this->doListenSocketSelect() ... - CALLED!');
 
                // Call super method
-               $this->doListenSocketSelect(':0');
+               $this->doListenSocketSelect();
 
                // Trace message
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UDP-LISTENER: EXIT!');
index d7a5b9ff318d4ed78acfc3b464e7a36e075c746b..73f6f0ef9a3157b0c716cb51d5da730b99b4736d 100644 (file)
@@ -85,29 +85,19 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke
         * @param       $infoInstance   An instance of a ShareableInfo class
         * @return      $key                    A string representation of the socket for the registry
         */
-       private function getSubRegistryKey (ShareableInfo $infoInstance) {
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: infoInstance=' . $infoInstance->__toString() . ' - CALLED!');
-
-               // Get address and port
-               $address = $infoInstance->getAddress();
-               $port    = $infoInstance->getPort();
-
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: address=' . $address . ',port=' . $port);
-
+       private function generateSubRegistryKeyFromInfoInstance (ShareableInfo $infoInstance) {
                // Get connection type and port number and add both together
-               $key = sprintf('%s:%s:%s:%s',
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-REGISTRY: infoInstance=%s - CALLED!', $infoInstance->__toString()));
+               $key = sprintf('%s:%s:%s:%s:%s',
                        $infoInstance->__toString(),
                        $infoInstance->getProtocolName(),
-                       $address,
-                       $port
+                       $infoInstance->getConnectionType(),
+                       $infoInstance->getAddress(),
+                       $infoInstance->getPort()
                );
 
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: key=' .  $key . ' - EXIT!');
-
                // Return resulting key
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-REGISTRY: key=%s - EXIT!', $key));
                return $key;
        }
 
@@ -177,7 +167,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke
                        $registryInstance = $this->getInstance($key);
 
                        // "Get" a key for the socket
-                       $socketKey = $this->getSubRegistryKey($infoInstance);
+                       $socketKey = $this->generateSubRegistryKeyFromInfoInstance($infoInstance);
 
                        // Debug message
                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: protocolName=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketInstance->getSocketResource()) . ']=' . $socketInstance->getSocketResource() . ',key=' . $key . ',socketKey=' . $socketKey . ' - Checking existence ...');
@@ -213,36 +203,39 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke
         */
        public function registerSocketInstance (ShareableInfo $infoInstance, StorableSocket $socketInstance) {
                // Is the socket already registered?
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: protocolName=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketInstance->getSocketResource()) . ']=' . $socketInstance->getSocketResource() . ' - CALLED!');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-REGISTRY: infoInstance->protocolName=%s,infoInstance->socketResource[%s]=%s - CALLED!', $infoInstance->getProtocolName(), gettype($socketInstance->getSocketResource()), $socketInstance->getSocketResource()));
                if ($this->isSocketRegistered($infoInstance, $socketInstance)) {
                        // Throw the exception
                        throw new SocketAlreadyRegisteredException(array($infoInstance, $socketInstance->getSocketResource()), BaseListener::EXCEPTION_SOCKET_ALREADY_REGISTERED);
                }
 
                // Does the instance exist?
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-REGISTRY: Checking if infoInstance=%s is registered ...', $infoInstance->__toString()));
                if (!$this->isInfoRegistered($infoInstance)) {
                        // No, not found so we create a sub registry (not needed to configure!)
                        $registryInstance = SubRegistry::createSubRegistry();
 
                        // Now we can create the sub-registry for this info
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-REGISTRY: Adding infoInstance=%s to registry ...', $infoInstance->__toString()));
                        $this->addInstance($this->getRegistryKeyFromInfo($infoInstance), $registryInstance);
                } else {
                        // Get the sub-registry back
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-REGISTRY: Getting sub-registry from infoInstance=%s ...', $infoInstance->__toString()));
                        $registryInstance = $this->getInstance($this->getRegistryKeyFromInfo($infoInstance));
                }
 
                // Get a key for sub-registries
-               $socketKey = $this->getSubRegistryKey($infoInstance);
+               $socketKey = $this->generateSubRegistryKeyFromInfoInstance($infoInstance);
 
                // We have a sub-registry, the socket key and the socket, now we need to put all together
-               /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: socketKey=' . $socketKey . ',socketResource[' . gettype($socketInstance->getSocketResource()) . ']=' . $socketInstance->getSocketResource() . ' - adding socket container instance ...');
+               /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-REGISTRY: socketKey=%s,socketResource[%s]=%s - adding socket container instance ...', $socketKey, gettype($socketInstance->getSocketResource()), $socketInstance->getSocketResource()));
                $registryInstance->addInstance($socketKey, $socketInstance);
 
                // Also register all instances from info instance in socket
                $socketInstance->registerInfoInstance($infoInstance);
 
                // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: EXIT!');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: EXIT!');
        }
 
        /**
@@ -254,26 +247,28 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke
         */
        public function getRegisteredSocketResource (Listenable $listenerInstance) {
                // The socket must be registered before we can return it
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY:listener=' . $listenerInstance->getProtocolName() . ' - CALLED!');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-REGISTRY: listenerInstance=%s - CALLED!', $listenerInstance->__toString()));
                if (!$this->isInfoRegistered($listenerInstance)) {
                        // Throw the exception
                        throw new NoSocketRegisteredException ($listenerInstance, self::EXCEPTION_SOCKET_NOT_REGISTERED);
                }
 
                // Now get the key from the listener
-               $key = $this->getRegistryKeyFromInfo($listenerInstance);
-
-               // And get the registry
-               $registryInstance = $this->getInstance($key);
+               $registryKey = $this->getRegistryKeyFromInfo($listenerInstance);
 
                // Get a socket key
-               $socketKey = $this->getSubRegistryKey($listenerInstance);
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-REGISTRY: registryKey=%s', $registryKey));
+               $socketKey = $this->generateSubRegistryKeyFromInfoInstance($listenerInstance);
+
+               // Get the registry
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-REGISTRY: socketKey=%s', $socketKey));
+               $registryInstance = $this->getInstance($registryKey);
 
                // And the final socket resource
                $socketInstance = $registryInstance->getInstance($socketKey);
 
                // Return the resource
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: listener=' . $listenerInstance->getProtocolName() . ',socketInstance[]=' . gettype($socketInstance) . ' - EXIT!');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-REGISTRY: listenerInstance=%s,socketInstance[]=%s - EXIT!', $listenerInstance->__toString(), gettype($socketInstance)));
                return $socketInstance;
        }