]> git.mxchange.org Git - hub.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Tue, 3 Nov 2020 19:08:17 +0000 (20:08 +0100)
committerRoland Häder <roland@mxchange.org>
Tue, 3 Nov 2020 19:08:17 +0000 (20:08 +0100)
- the SocketFactory class was invoking complicated createConnectionFromPackageInstance()
  method which didn't fit naming-convention. It is now renamed to
  "create<ClassName>" scheme and can be created by default ObjectFactory's
  factory methods.
- improved some debug lines

Signed-off-by: Roland Häder <roland@mxchange.org>
application/hub/classes/container/socket/class_SocketContainer.php
application/hub/classes/factories/socket/class_SocketFactory.php
application/hub/classes/helper/connection/ipv4/tcp/class_TcpConnectionHelper.php
application/hub/classes/helper/connection/ipv4/udp/class_UdpConnectionHelper.php

index e3e9506cf43b78d1f51b6a611c2e56809bd1e5cc..c45ebf4eff8055db40e32ade1196e44060b2a8cf 100644 (file)
@@ -384,7 +384,6 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                // Return it
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: recipientPort=%d - EXIT!', strtoupper($this->getSocketProtocol()), intval($recipientPort)));
                return $recipientPort;
-
        }
 
        /**
@@ -781,11 +780,10 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                 * PHP_NORMAL_READ, this line will endless block. This script does only
                 * provide simultanous or faked threads, not real.
                 */
-               /* EXTREME-NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
                $rawData = socket_read($this->getSocketResource(), $this->getConfigInstance()->getConfigEntry('tcp_buffer_length'), PHP_BINARY_READ);
 
                // Return it
-               /* EXTREME-NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: rawData[%s]()=%d - EXIT!', strtoupper($this->getSocketProtocol()), gettype($rawData), strlen($rawData)));
+               /* EXTREME-NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s,rawData[%s]=%s - EXIT!', strtoupper($this->getSocketProtocol()), $this->getSocketResource(), gettype($rawData), $rawData));
                return $rawData;
        }
 
@@ -823,19 +821,14 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
         * @return      $result         Whether the option has been set
         */
        public function setSocketTimeoutOptions () {
-               // Trace message
+               // Call setter method with configured values
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
-
-               // Array for timeout settings
-               $options  = array(
+               $result = $this->setSocketOption(SOL_SOCKET, SO_RCVTIMEO, [
                        // Seconds
                        'sec'  => $this->getConfigInstance()->getConfigEntry($this->getSocketProtocol() . '_socket_accept_wait_sec'),
                        // Milliseconds
-                       'usec' => $this->getConfigInstance()->getConfigEntry($this->getSocketProtocol() . '_socket_accept_wait_usec')
-               );
-
-               // Call inner method
-               $result = $this->setSocketOption(SOL_SOCKET, SO_RCVTIMEO, $options);
+                       'usec' => $this->getConfigInstance()->getConfigEntry($this->getSocketProtocol() . '_socket_accept_wait_usec'),
+               ]);
 
                // Return result
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result[%s]=%d - EXIT!', strtoupper($this->getSocketProtocol()), gettype($result), intval($result)));
@@ -849,13 +842,11 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
         */
        public function enableSocketOutOfBandData () {
                // Call inner method
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getSocketResource()));
                $result = $this->setSocketOption(SOL_SOCKET, SO_OOBINLINE, 1);
 
-               // Trace message
-
                // Return result
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result[%s]=%d - EXIT!', strtoupper($this->getSocketProtocol()), gettype($result), intval($result)));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result[%s]=%d - EXIT!', strtoupper($this->getSocketProtocol()), gettype($result), intval($result)));
                return $result;
        }
 
@@ -868,7 +859,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
         */
        public function clearLastSocketError () {
                // Should be valid socket
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Clearing socket error - CALLED!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Clearing socket error - CALLED!');
                if (!$this->isValidSocket()) {
                        // Throw exception
                        throw new InvalidSocketException(array($this), self::EXCEPTION_INVALID_SOCKET);
@@ -881,7 +872,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                socket_clear_error($this->getSocketResource());
 
                // Trace message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Error cleared - EXIT!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Error cleared - EXIT!');
        }
 
        /**
@@ -892,17 +883,13 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
         * @return      void
         */
        public function registerInfoInstance (ShareableInfo $infoInstance) {
-               // Trace message
-               //* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Calling infoInstance->getListenerInstance() - CALLED!', strtoupper($this->getSocketProtocol())));
-
                // Get listener/helper from info class
+               //* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Calling infoInstance->getListenerInstance() - CALLED!', strtoupper($this->getSocketProtocol())));
                $listenerInstance = $infoInstance->getListenerInstance();
                $helperInstance = $infoInstance->getHelperInstance();
 
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: listenerInstance[]=' . gettype($listenerInstance) . ',helperInstance[]=' . gettype($helperInstance));
-
                // Is there a listener instance set?
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: listenerInstance[]=' . gettype($listenerInstance) . ',helperInstance[]=' . gettype($helperInstance));
                if ($listenerInstance instanceof Listenable) {
                        // Set it here for later usage
                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Setting listenerInstance=' . $listenerInstance->__toString() . ' ...');
@@ -934,7 +921,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
        public function writeBufferToSocketByArray (array &$socketBuffer, &$sentBytes) {
                // Should be valid socket
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: socketBuffer()=%d,sentBytes=%d - CALLED!', strtoupper($this->getSocketProtocol()), count($socketBuffer), $sentBytes));
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: socketBuffer=%s', strtoupper($this->getSocketProtocol()), print_r($socketBuffer, TRUE)));
+               //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: socketBuffer=%s', strtoupper($this->getSocketProtocol()), print_r($socketBuffer, TRUE)));
                if (!$this->isValidSocket()) {
                        // Throw exception
                        throw new InvalidSocketException(array($this), self::EXCEPTION_INVALID_SOCKET);
index 5e5281c931ba0b9fafaa62c6c0b0d4cf0d54247a..b00926d4d9b490439d237d0e504c7f31364393a2 100644 (file)
@@ -64,12 +64,13 @@ class SocketFactory extends ObjectFactory {
        public static function createSocketFromPackageInstance (DeliverablePackage $packageInstance, HandleableProtocol $protocolInstance) {
                // Init instance
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: packageInstance=%s,protocolInstance=%s - CALLED!', $packageInstance->__toString(), $protocolInstance->__toString()));
+               //* DEBUG-DIE: */ die(sprintf('[%s:%d]: packageInstance=%s', __METHOD__, __LINE__, print_r($packageInstance, TRUE)));
                $socketInstance = NULL;
 
                // Construct registry key
                $registryKey = sprintf('socket_%s_%s',
                        $protocolInstance->getProtocolName(),
-                       $packageInstance->getRecipientType()
+                       $packageInstance->getRecipientUnl()
                );
 
                // Is the key there?
@@ -81,12 +82,8 @@ class SocketFactory extends ObjectFactory {
                        // Debug message
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: Using socketResource[%s]=%s from registry.', gettype($socketInstance->getSocketResource()), $socketInstance->getSocketResource()));
                } else {
-                       // Construct configuration entry for object factory and get it
-                       $className = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($protocolInstance->getProtocolName() . '_connection_helper_class');
-
-                       // And call the static method
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: Going to use className=%s for creating a socket resource ...', $className));
-                       $socketInstance = call_user_func($className . '::createConnectionFromPackageInstance', $packageInstance);
+                       // Invoke inner factory
+                       $socketInstance = self::createObjectByConfiguredName(sprintf('%s_connection_helper_class', $protocolInstance->getProtocolName()), array($packageInstance));
 
                        // Register it with the registry
                        GenericRegistry::getRegistry()->addInstance($registryKey, $socketInstance);
index 1a764f50970b658b0308a26655b47dc99336f651..27d8b751b30d87652f767d2e688993906d3b8221 100644 (file)
@@ -58,7 +58,7 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection
         * @param       $packageInstance                An instance of a DeliverablePackage class
         * @return      $socketInstance         An instance of a StorableSocket class
         */
-       public static function createConnectionFromPackageInstance (DeliverablePackage $packageInstance) {
+       public static function createTcpConnectionHelper (DeliverablePackage $packageInstance) {
                // Create an instance
                $helperInstance = new TcpConnectionHelper();
 
index 39ac6281708cf779bb7399c89e3c043800cf6d4f..07baaec701d2d02b812eccd1877e0c430c160e33 100644 (file)
@@ -53,7 +53,7 @@ class UdpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection
         * @param       $packageInstance                An instance of a DeliverablePackage class
         * @return      $socketInstance         An instance of a StorableSocket class
         */
-       public static function createConnectionFromPackageInstance (DeliverablePackage $packageInstance) {
+       public static function createUdpConnectionHelper (DeliverablePackage $packageInstance) {
                $this->debugBackTrace('Unfinished method, packageInstance=' . print_r($packageInstance, TRUE));
        }