]> git.mxchange.org Git - hub.git/commitdiff
Continued a bit:
authorRoland Häder <roland@mxchange.org>
Mon, 22 May 2017 13:25:37 +0000 (15:25 +0200)
committerRoland Häder <roland@mxchange.org>
Fri, 21 Aug 2020 16:50:07 +0000 (18:50 +0200)
- implemented enableSocketReuseAddress()
- imported (Base)Iterator
- added missing namespaces
- created new namespaces (also template)
- cleared up now obsolete code as StorableSocket is now there
- renamed method to listenToSocket()

Signed-off-by: Roland Häder <roland@mxchange.org>
23 files changed:
application/hub/classes/container/socket/class_SocketContainer.php
application/hub/classes/factories/socket/class_SocketFactory.php
application/hub/classes/helper/connection/class_BaseConnectionHelper.php
application/hub/classes/helper/messages/crypto/class_CryptoRandomUnitMessageHelper.php
application/hub/classes/iterator/hub/class_HubPingIterator.php
application/hub/classes/iterator/network/class_NetworkListenIterator.php
application/hub/classes/iterator/pool/handler/class_Handler
application/hub/classes/iterator/pool/handler/class_HandlerPoolIterator.php
application/hub/classes/iterator/pool/monitor/class_MonitorPoolIterator.php
application/hub/classes/iterator/pool/shutdown/class_Shutdown
application/hub/classes/iterator/pool/shutdown/class_ShutdownPoolIterator.php
application/hub/classes/iterator/pool/tasks/class_TaskPoolIterator.php
application/hub/classes/iterator/producer/keys/class_TestUnitKeyProducerIterator.php
application/hub/classes/listener/class_
application/hub/classes/listener/class_BaseListener.php
application/hub/classes/listener/class_BaseListenerDecorator.php
application/hub/classes/package/class_NetworkPackage.php
application/hub/classes/registry/socket/class_SocketRegistry.php
application/hub/config.php
application/hub/interfaces/container/socket/class_StorableSocket.php
application/hub/interfaces/helper/connections/class_ConnectionHelper.php
application/hub/interfaces/helper/messages/class_MessageHelper.php
application/hub/interfaces/listener/class_Listenable.php

index ff3bcb0650f72175cedc965460ff7c843cb9e0a7..89d5d914e6963600c886f79746d14aa05f995203 100644 (file)
@@ -413,7 +413,7 @@ class SocketContainer extends BaseContainer implements StorableSocket, Visitable
         * @return      $result         Result from listening on socket
         * @throws      InvalidSocketException  If stored socket is invalid
         */
-       public function listenOnSocket () {
+       public function listenToSocket () {
                // Should be valid socket
                if (!$this->isValidSocket()) {
                        // Throw exception
@@ -447,6 +447,26 @@ class SocketContainer extends BaseContainer implements StorableSocket, Visitable
                return $result;
        }
 
+       /**
+        * Tries to enable option "reuse address"
+        *
+        * @return      void
+        * @throws      InvalidSocketException  If stored socket is invalid
+        */
+       public function enableSocketReuseAddress () {
+               // Should be valid socket
+               if (!$this->isValidSocket()) {
+                       // Throw exception
+                       throw new InvalidSocketException(array($this, $this->getSocketResource()), self::EXCEPTION_INVALID_SOCKET);
+               } // END - if
+
+               // Tries to set option
+               $result = socket_set_option($this->getSocketResource(), SOL_SOCKET, SO_REUSEADDR, 1);
+
+               // Return result
+               return $result;
+       }
+
        /**
         * Do the shutdown sequence for this connection helper
         *
index b553e69053022dc2be110f638ea3e69aed8a9008..c652e29fff8c4b2defdb1c642bdf9433a66dffc7 100644 (file)
@@ -162,7 +162,7 @@ class SocketFactory extends ObjectFactory {
 
                // Start listen for connections
                self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Listening for connections.');
-               if (!$socketInstance->listenOnSocket()) {
+               if (!$socketInstance->listenToSocket()) {
                        // Handle this socket error with a faked recipientData array
                        $socketInstance->handleSocketError(__METHOD__, __LINE__, array_values($packageData));
                } // END - if
@@ -268,7 +268,6 @@ class SocketFactory extends ObjectFactory {
                } // END - if
 
                // Set the option to reuse the port
-               // @TODO: , SOL_SOCKET, SO_REUSEADDR, 1
                self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Enabling re-use address ...');
                if (!$socketInstance->enableSocketReuseAddress()) {
                        // Handle this socket error with a faked recipientData array
index 3ca61c854a510891175d7bbea9773413660659c1..b5b8ca22fbb53b70d97891d47382fd12f8966658 100644 (file)
@@ -55,11 +55,6 @@ class BaseConnectionHelper extends BaseHubSystemHelper implements Visitable, Reg
         */
        const CONNECTION_TYPE_SERVER   = 'server';
 
-       /**
-        * Name of used protocol for this connection
-        */
-       private $connectionType = 'invalid';
-
        /**
         * (IP) Adress used
         */
@@ -138,25 +133,6 @@ class BaseConnectionHelper extends BaseHubSystemHelper implements Visitable, Reg
                return $class;
        }
 
-       /**
-        * Getter for connection type
-        *
-        * @return      $connectionType         Name of used protocol in this connection
-        */
-       public final function getConnectionType () {
-               return $this->connectionType;
-       }
-
-       /**
-        * Setter for connection type
-        *
-        * @param       $connectionType         Name of used protocol in this connection
-        * @return      void
-        */
-       protected final function setConnectionType ($connectionType) {
-               $this->connectionType = $connectionType;
-       }
-
        /**
         * Getter for IP address
         *
index f345ca7d83e326d60ccde2ca82a2214aa330d0af..8940f1cfa25f3f1b53fe4d53171d83bb0486044b 100644 (file)
@@ -83,7 +83,5 @@ class CryptoRandomUnitMessageHelper extends BaseMessageHelper implements Message
                // And return it
                return $iteratorInstance;
        }
-}
 
-// [EOF]
-?>
+}
index 8f65db578661e43b2b0edccd69282d3a53b4c825..4600d0ef9791341fd351d25e41cc3b3d78037039 100644 (file)
@@ -1,4 +1,13 @@
 <?php
+// Own namespace
+namespace Hub\Iterator\Ping;
+
+// Import framework stuff
+use CoreFramework\Iterator\BaseIterator;
+
+// Import SPL stuff
+use \Iterator;
+
 /**
  * A HubPing iterator
  *
index 9d147ac9b8dd15a6b868f41974a84a3b710d3014..c871039f6dd0beee4c37e14cddd7caf3426f0b5b 100644 (file)
@@ -3,8 +3,12 @@
 namespace Hub\Iterator\Network\Listener;
 
 // Import framework stuff
+use CoreFramework\Iterator\BaseIterator;
 use CoreFramework\Lists\Listable;
 
+// Import SPL stuff
+use \Iterator;
+
 /**
  * A NetworkListen iterator
  *
index 9ec43c12469cf9d693e47bbb14c0ce0d277ab5fd..acbb5eb321b14c66b2993f611e132a1844ce6bc1 100644 (file)
@@ -1,4 +1,13 @@
 <?php
+// Own namespace
+namespace Hub\Iterator\Handler\;
+
+// Import framework stuff
+use CoreFramework\Iterator\BaseIterator;
+
+// Import SPL stuff
+use \Iterator;
+
 /**
  * A handler ??? iterator
  *
index fd6be6ebe506936d6361ae8fea8bd61a8982e0a5..bb100c97d929b36a1208399f591b1e665ec02c60 100644 (file)
@@ -3,8 +3,12 @@
 namespace Hub\Iterator\Handler\Pool;
 
 // Import framework stuff
+use CoreFramework\Iterator\BaseIterator;
 use CoreFramework\Lists\Listable;
 
+// Import SPL stuff
+use \Iterator;
+
 /**
  * A HandlerPool iterator
  *
index b35931d423e4d24539a05d7312023edc6f41cb0e..04ce447daeaf804868234a9469773d41c06396f5 100644 (file)
@@ -3,8 +3,12 @@
 namespace Hub\Iterator\Pool\Monitor;
 
 // Import framework stuff
-use CoreFramework\Registry\Registerable;
+use CoreFramework\Iterator\BaseIterator;
 use CoreFramework\Lists\Listable;
+use CoreFramework\Registry\Registerable;
+
+// Import SPL stuff
+use \Iterator;
 
 /**
  * A MonitorPool iterator
index 5e0aaa843ff082ea4034f336fd419af1c3ed3493..998c3aa6074362a58ec59f46e668a8ae53b9f108 100644 (file)
@@ -1,4 +1,13 @@
 <?php
+// Own namespace
+namespace Hub\Iterator\Shutdown\;
+
+// Import framework stuff
+use CoreFramework\Iterator\BaseIterator;
+
+// Import SPL stuff
+use \Iterator;
+
 /**
  * A shutdown ??? iterator
  *
index 26d60572d6bf0fc4235011a0bbc062b160442f0f..f1890c6b355d5bf2640e9d776dba28c1d9c7f474 100644 (file)
@@ -1,10 +1,14 @@
 <?php
 // Own namespace
-namespace Hub\Iterator\Pool\Shutdown;
+namespace Hub\Iterator\Shutdown\Pool;
 
 // Import framework stuff
+use CoreFramework\Iterator\BaseIterator;
 use CoreFramework\Lists\Listable;
 
+// Import SPL stuff
+use \Iterator;
+
 /**
  * A ShutdownPool iterator
  *
index 6a45eddce4091ee30457cda76e7806728099f25f..5084d71dbbaa926e8d1c2796503c509c0cc28d4a 100644 (file)
@@ -6,6 +6,9 @@ namespace Hub\Iterator\Pool\Task;
 use CoreFramework\Lists\Listable;
 use CoreFramework\Registry\Registerable;
 
+// Import SPL stuff
+use \Iterator;
+
 /**
  * A TaskPool iterator
  *
index aff00bc082453413374ccfea2fc4460f1432c2f9..498b28fb4bf279b5ba15f7ae0c8d2589089cf6c8 100644 (file)
@@ -2,8 +2,12 @@
 // Own namespace
 namespace Hub\Iterator\Producer\TestUnitKey;
 
-// Import Framework stuff
+// Import framework stuff
 use CoreFramework\Generic\UnsupportedOperationException;
+use CoreFramework\Iterator\BaseIterator;
+
+// Import SPL stuff
+use \Iterator;
 
 /**
  * A TestUnitKeyProducer iterator
index 6aaf16f48f649080324c06d13d3ed16d674db083..db53113793357d066a278cd08d0b415c41a61e9d 100644 (file)
@@ -97,13 +97,4 @@ class ???Listener extends BaseListener implements Listenable {
                $this->partialStub('Need to implement this method.') {
        }
 
-       /**
-        * Getter for connection type
-        *
-        * @return      $connectionType         Connection type for this listener
-        */
-       public function getConnectionType () {
-               $this->partialStub('Need to implement this method.') {
-       }
-
 }
index 555a71230e95251fcb80bc9d7e9ae6778b4eb599..e1aef689a9a8d98e50f948ce33861f8c8f5cfcea 100644 (file)
@@ -62,11 +62,6 @@ class BaseListener extends BaseHubSystem implements Visitable {
         */
        private $listenPort = 0; // This port MUST be changed by your application
 
-       /**
-        * Whether we are in blocking or non-blocking mode (default: non-blocking
-        */
-       private $blockingMode = false;
-
        /**
         * A peer pool instance
         */
@@ -146,25 +141,6 @@ class BaseListener extends BaseHubSystem implements Visitable {
                $this->setListenPort($this->getConfigInstance()->getConfigEntry($configEntry));
        }
 
-       /**
-        * Setter for blocking-mode
-        *
-        * @param       $blockingMode   Whether blocking-mode is disabled (default) or enabled
-        * @return      void
-        */
-       protected final function setBlockingMode ($blockingMode) {
-               $this->blockingMode = (boolean) $blockingMode;
-       }
-
-       /**
-        * Checks whether blocking-mode is enabled or disabled
-        *
-        * @return      $blockingMode   Whether blocking mode is disabled or enabled
-        */
-       public final function isBlockingModeEnabled () {
-               return $this->blockingMode;
-       }
-
        /**
         * Setter for peer pool instance
         *
@@ -184,16 +160,6 @@ class BaseListener extends BaseHubSystem implements Visitable {
                return $this->poolInstance;
        }
 
-       /**
-        * Getter for connection type
-        *
-        * @return      $connectionType         Connection type for this listener
-        */
-       public final function getConnectionType () {
-               // Wrap the real getter
-               return $this->getProtocolName();
-       }
-
        /**
         * Registeres the given socket resource for "this" listener instance. This
         * will be done in a seperate class to allow package writers to use it
index 2b438e5652bb91da5e97df1417cff2475e451836..abd07df8314d0045bb9fb9750518edc90f610800 100644 (file)
@@ -79,15 +79,6 @@ class BaseListenerDecorator extends BaseDecorator implements Visitable {
                return $this->getListenerInstance()->getListenPort();
        }
 
-       /**
-        * Getter for connection type
-        *
-        * @return      $connectionType         Connection type for this listener
-        */
-       public final function getConnectionType () {
-               return $this->getListenerInstance()->getConnectionType();
-       }
-
        /**
         * Accepts the visitor to process the visit "request"
         *
index 41584f769776b23f55764db9e050c08088c2f5de..5276e079b58f46c70309d0c2775d3c91a37c2deb 100644 (file)
@@ -28,6 +28,9 @@ use CoreFramework\Socket\InvalidSocketException;
 use CoreFramework\Visitor\Visitable;
 use CoreFramework\Visitor\Visitor;
 
+// Import SPL stuff
+use \Iterator;
+
 /**
  * A NetworkPackage class. This class implements Deliverable and Receivable
  * because all network packages should be deliverable to other nodes and
index 18699ec3026caa3b0f7d4c3d5fc7c4d9596f42ca..d3de513d7859d3ce32ef456531e06a65819e6a4f 100644 (file)
@@ -253,7 +253,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke
         */
        public function getRegisteredSocketResource (Listenable $listenerInstance) {
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY:listener=' . $listenerInstance->getConnectionType() . ' - CALLED!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY:listener=' . $listenerInstance->getProtocolName() . ' - CALLED!');
 
                // The socket must be registered before we can return it
                if (!$this->isInfoRegistered($listenerInstance)) {
@@ -274,7 +274,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke
                $socketInstance = $registryInstance->getInstance($socketKey);
 
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY:listener=' . $listenerInstance->getConnectionType() . ',socketResource[]=' . gettype($socketInstance) . ' - EXIT!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY:listener=' . $listenerInstance->getProtocolName() . ',socketResource[]=' . gettype($socketInstance) . ' - EXIT!');
 
                // Return the resource
                return $socketInstance;
index 79997cf3d0e77d655f71682f1c199fe28aa86fb5..314073e106ac70169facc0ae46ea97dba135db54 100644 (file)
@@ -82,16 +82,16 @@ $cfg->setConfigEntry('socket_file_listener_class', 'Hub\Listener\Socket\SocketFi
 $cfg->setConfigEntry('socket_file_decorator_listener_class', 'Hub\Listener\Socket\SocketFileListenerDecorator');
 
 // CFG: NODE-TCP-LISTENER-CLASS
-$cfg->setConfigEntry('node_tcp_listener_class', 'HubTcpListenerDecorator');
+$cfg->setConfigEntry('node_tcp_listener_class', 'Hub\Listener\Hub\Tcp\HubTcpListenerDecorator');
 
 // CFG: NODE-UDP-LISTENER-CLASS
-$cfg->setConfigEntry('node_udp_listener_class', 'HubUdpListenerDecorator');
+$cfg->setConfigEntry('node_udp_listener_class', 'Hub\Listener\Hub\Udp\HubUdpListenerDecorator');
 
 // CFG: CLIENT-TCP-LISTENER-CLASS
-$cfg->setConfigEntry('client_tcp_listener_class', 'ClientTcpListenerDecorator');
+$cfg->setConfigEntry('client_tcp_listener_class', 'Hub\Listener\Client\Tcp\ClientTcpListenerDecorator');
 
 // CFG: CLIENT-UDP-LISTENER-CLASS
-$cfg->setConfigEntry('client_udp_listener_class', 'ClientUdpListenerDecorator');
+$cfg->setConfigEntry('client_udp_listener_class', 'Hub\Listener\Client\Udp\ClientUdpListenerDecorator');
 
 // CFG: NODE-POOL-CLASS
 $cfg->setConfigEntry('node_pool_class', 'Hub\Pool\Peer\DefaultPeerPool');
@@ -109,16 +109,16 @@ $cfg->setConfigEntry('shutdown_pool_iterator_class', 'ShutdownPoolIterator');
 $cfg->setConfigEntry('handler_pool_iterator_class', 'HandlerPoolIterator');
 
 // CFG: NETWORK-LISTEN-ITERATOR-CLASS
-$cfg->setConfigEntry('network_listen_iterator_class', 'NetworkListenIterator');
+$cfg->setConfigEntry('network_listen_iterator_class', 'Hub\Iterator\Network\Listener\NetworkListenIterator');
 
 // CFG: SOCKET-LISTEN-ITERATOR-CLASS
 $cfg->setConfigEntry('socket_listen_iterator_class', 'CoreFramework\Iterator\DefaultIterator');
 
 // CFG: TCP-RAW-DATA-HANDLER-CLASS
-$cfg->setConfigEntry('tcp_raw_data_handler_class', 'TcpRawDataHandler');
+$cfg->setConfigEntry('tcp_raw_data_handler_class', 'Hub\Handler\Network\RawData\Tcp\TcpRawDataHandler');
 
 // CFG: UDP-RAW-DATA-HANDLER-CLASS
-$cfg->setConfigEntry('udp_raw_data_handler_class', 'UdpRawDataHandler');
+$cfg->setConfigEntry('udp_raw_data_handler_class', 'Hub\Handler\Network\RawData\Udp\UdpRawDataHandler');
 
 // CFG: SOCKET-RAW-DATA-HANDLER-CLASS
 $cfg->setConfigEntry('socket_raw_data_handler_class', 'Hub\Handler\Network\Socket\RawData\SocketRawDataHandler');
index 07de27e65f160c7cc76e4cf522adb5b0771850ba..b45438da67e8ac8de05bf6aec84ea38581dab369 100644 (file)
@@ -73,7 +73,7 @@ interface StorableSocket extends FrameworkInterface {
         * @return      $result         Result from listening on socket
         * @throws      InvalidSocketException  If stored socket is invalid
         */
-       function listenOnSocket ();
+       function listenToSocket ();
 
        /**
         * Tries to set non-blocking I/O on stored socket
@@ -83,6 +83,14 @@ interface StorableSocket extends FrameworkInterface {
         */
        function enableSocketNonBlocking ();
 
+       /**
+        * Tries to enable option "reuse address"
+        *
+        * @return      void
+        * @throws      InvalidSocketException  If stored socket is invalid
+        */
+       function enableSocketReuseAddress ();
+
        /**
         * Some "getter" for peer address/port from stored socket
         *
index a053edcea10be9821c8100aa1350b2a9ae06ca48..a5c805badc9b666e3e5e8d7e771cd26133448041 100644 (file)
@@ -54,13 +54,6 @@ interface ConnectionHelper extends HubHelper {
         */
        function getConnectionPort ();
 
-       /**
-        * Getter for connection type
-        *
-        * @return      $type   Type of connection
-        */
-       function getConnectionType ();
-
        /**
         * Getter for IP address
         *
@@ -84,7 +77,5 @@ interface ConnectionHelper extends HubHelper {
         * @return      $shuttedDown    Whether this connection is shutted down
         */
        function isShuttedDown ();
-}
 
-// [EOF]
-?>
+}
index 71014a3045853abf50150fd477df76acfaba1016..05bd92238bf729263854d4b7345a65781d0cac72 100644 (file)
@@ -43,7 +43,5 @@ interface MessageHelper extends Helper {
         * @return      $iteratorInstance       An instance of a Iterator class
         */
        function getKeyIterator ();
-}
 
-// [EOF]
-?>
+}
index 5d9d17d949f651b6dba91fe390cf3da3720c20cf..e6470884cec67c4f8a9f3a4af5a140b8f09964dd 100644 (file)
@@ -73,13 +73,6 @@ interface Listenable extends HubInterface {
         */
        function getListenPort ();
 
-       /**
-        * Getter for connection type
-        *
-        * @return      $connectionType         Connection type for this listener
-        */
-       function getConnectionType ();
-
        /**
         * Getter for peer pool instance
         *