]> git.mxchange.org Git - hub.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sun, 21 May 2017 20:25:26 +0000 (22:25 +0200)
committerRoland Häder <roland@mxchange.org>
Fri, 21 Aug 2020 16:50:05 +0000 (18:50 +0200)
- setter/getter for socket instance is now in BaseListener
- imported StorableSocket
- moved constants to Poolable interface
- updated core framework

Signed-off-by: Roland Häder <roland@mxchange.org>
14 files changed:
application/hub/classes/factories/socket/class_SocketFactory.php
application/hub/classes/handler/network/tcp/class_TcpRawDataHandler.php
application/hub/classes/handler/network/udp/class_UdpRawDataHandler.php
application/hub/classes/handler/raw_data/network/class_BaseRawDataHandler.php
application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php
application/hub/classes/listener/class_BaseListener.php
application/hub/classes/package/class_NetworkPackage.php
application/hub/classes/pools/class_BasePool.php
application/hub/classes/pools/peer/class_DefaultPeerPool.php
application/hub/classes/registry/socket/class_SocketRegistry.php
application/hub/interfaces/class_HubInterface.php
application/hub/interfaces/listener/class_Listenable.php
application/hub/interfaces/pool/class_Poolable.php
core

index 8262f2ce945242b03b4fafaad1a3a2f0103c4461..44cd11ff7818240ffef9893fbfb24bd9da80c5f0 100644 (file)
@@ -3,6 +3,7 @@
 namespace Hub\Factory\Socket;
 
 // Import application-specific stuff
+use Hub\Container\Socket\StorableSocket;
 use Hub\Handler\Protocol\HandleableProtocol;
 use Hub\Listener\BaseListener;
 use Hub\Listener\Listenable;
index 460835bb6871b169fe8e591fb79b815f0b2aa63c..ee1f41f526d61301e9b5f04fb72240cbd718610d 100644 (file)
@@ -5,7 +5,7 @@ namespace Hub\Handler\Network\RawData\Tcp;
 // Import application-specific stuff
 use Hub\Handler\RawData\BaseRawDataHandler;
 use Hub\Network\Networkable;
-use Hub\Pool\BasePool;
+use Hub\Pool\Poolable;
 
 /**
  * A TCP raw data handler
@@ -65,7 +65,7 @@ class TcpRawDataHandler extends BaseRawDataHandler implements Networkable {
         */
        public function processRawDataFromResource (array $socketArray) {
                // Check the resource
-               if ((!isset($socketArray[BasePool::SOCKET_ARRAY_INSTANCE])) || (!is_resource($socketArray[BasePool::SOCKET_ARRAY_INSTANCE]))) {
+               if ((!isset($socketArray[Poolable::SOCKET_ARRAY_INSTANCE])) || (!is_resource($socketArray[Poolable::SOCKET_ARRAY_INSTANCE]))) {
                        // Throw an exception
                        throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
                } // END - if
@@ -74,33 +74,33 @@ class TcpRawDataHandler extends BaseRawDataHandler implements Networkable {
                $this->setErrorCode(self::SOCKET_ERROR_UNHANDLED);
 
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-HANDLER: Handling TCP package from resource=' . $socketArray[BasePool::SOCKET_ARRAY_INSTANCE] . ',type=' . $socketArray[BasePool::SOCKET_ARRAY_CONN_TYPE] . ',last error=' . socket_strerror($this->lastSocketError));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-HANDLER: Handling TCP package from resource=' . $socketArray[Poolable::SOCKET_ARRAY_INSTANCE] . ',type=' . $socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE] . ',last error=' . socket_strerror($this->lastSocketError));
 
                /*
                 * Read the raw data from socket. If you change PHP_BINARY_READ to
                 * PHP_NORMAL_READ, this line will endless block. This script does only
                 * provide simultanous threads, not real.
                 */
-               $rawData = socket_read($socketArray[BasePool::SOCKET_ARRAY_INSTANCE], $this->getConfigInstance()->getConfigEntry('tcp_buffer_length'), PHP_BINARY_READ);
+               $rawData = socket_read($socketArray[Poolable::SOCKET_ARRAY_INSTANCE], $this->getConfigInstance()->getConfigEntry('tcp_buffer_length'), PHP_BINARY_READ);
 
                // Get socket error code back
-               $this->lastSocketError = socket_last_error($socketArray[BasePool::SOCKET_ARRAY_INSTANCE]);
+               $this->lastSocketError = socket_last_error($socketArray[Poolable::SOCKET_ARRAY_INSTANCE]);
 
                // Debug output of read data length
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-HANDLER: rawData[' . gettype($rawData) . ']=' . strlen($rawData) . ',MD5=' . md5($rawData) . ',resource=' . $socketArray[BasePool::SOCKET_ARRAY_INSTANCE] . ',error=' . socket_strerror($this->lastSocketError));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-HANDLER: rawData[' . gettype($rawData) . ']=' . strlen($rawData) . ',MD5=' . md5($rawData) . ',resource=' . $socketArray[Poolable::SOCKET_ARRAY_INSTANCE] . ',error=' . socket_strerror($this->lastSocketError));
                //* NOISY-DEBUG: */ if ($rawData !== FALSE) self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-HANDLER: rawData=' . $rawData);
 
                // Is it valid?
                if ($this->lastSocketError == 11) {
                        // Debug message
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-HANDLER: Ignoring error 11 (Resource temporary unavailable) from socket resource=' . $socketArray[BasePool::SOCKET_ARRAY_INSTANCE]);
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-HANDLER: Ignoring error 11 (Resource temporary unavailable) from socket resource=' . $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]);
 
                        /*
                         * Error code 11 (Resource temporary unavailable) can be safely
                         * ignored on non-blocking sockets. The socket is currently not
                         * sending any data.
                         */
-                        socket_clear_error($socketArray[BasePool::SOCKET_ARRAY_INSTANCE]);
+                        socket_clear_error($socketArray[Poolable::SOCKET_ARRAY_INSTANCE]);
 
                         // Skip any further processing
                         return;
index 39e8d123f5bc609570a41f1190fe55e87da7fbb1..2c3e0a911274ed195c13be9117bb6cef2688ba04 100644 (file)
@@ -5,7 +5,7 @@ namespace Hub\Handler\RawData\Udp;
 // Import application-specific stuff
 use Hub\Handler\RawData\BaseRawDataHandler;
 use Hub\Network\Networkable;
-use Hub\Pool\BasePool;
+use Hub\Pool\Poolable;
 
 /**
  * A UDP raw data handler
@@ -67,13 +67,13 @@ class UdpRawDataHandler extends BaseRawDataHandler implements Networkable {
         */
        public function processRawDataFromResource (array $socketArray) {
                // Check the resource
-               if ((!isset($socketArray[BasePool::SOCKET_ARRAY_INSTANCE])) || (!is_resource($socketArray[BasePool::SOCKET_ARRAY_INSTANCE]))) {
+               if ((!isset($socketArray[Poolable::SOCKET_ARRAY_INSTANCE])) || (!is_resource($socketArray[Poolable::SOCKET_ARRAY_INSTANCE]))) {
                        // Throw an exception
                        throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
                } // END - if
 
                // Implement processing here
-               $this->partialStub('Please implement this method. resource=' . $socketArray[BasePool::SOCKET_ARRAY_INSTANCE] . ',type=' . $socketArray[BasePool::SOCKET_ARRRAY_CONN_TYPE]);
+               $this->partialStub('Please implement this method. resource=' . $socketArray[Poolable::SOCKET_ARRAY_INSTANCE] . ',type=' . $socketArray[Poolable::SOCKET_ARRRAY_CONN_TYPE]);
        }
 }
 
index 2544d52899016756a9e594a8e7faadbef31e0b83..3374872e2162c973b7c195f5deaf6385760fefbc 100644 (file)
@@ -3,6 +3,7 @@
 namespace Hub\Handler\RawData;
 
 // Import application-specific stuff
+use Hub\Container\Socket\StorableSocket;
 use Hub\Network\Package\NetworkPackage;
 
 // Import framework stuff
@@ -68,7 +69,7 @@ class BaseRawDataHandler extends BaseHandler {
                parent::__construct($className);
 
                // Set error code to 'unknown'
-               $this->setErrorCode(self::SOCKET_ERROR_UNKNOWN);
+               $this->setErrorCode(StorableSocket::SOCKET_ERROR_UNKNOWN);
 
                // Init stacker instance for processed raw data
                $stackInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_stacker_class');
index 0af6dbc8a132738f7a97552d3b42283ee0cc97c2..09dfafda259a2abc5458293c0e7c9ba53e339949 100644 (file)
@@ -3,7 +3,6 @@
 namespace Hub\Helper\Connection\IpV4;
 
 // Import application-specific stuff
-use Hub\Container\Socket\StorableSocket;
 use Hub\Helper\Connection\BaseConnectionHelper;
 use Hub\Locator\Node\LocateableNode;
 
index b2e5e7ffec648a8d7cff4a10ecbbd1bcbbb5f729..555a71230e95251fcb80bc9d7e9ae6778b4eb599 100644 (file)
@@ -9,6 +9,7 @@ use Hub\Generic\BaseHubSystem;
 use Hub\Helper\Connection\BaseConnectionHelper;
 use Hub\Network\Package\NetworkPackage;
 use Hub\Pool\Peer\PoolablePeer;
+use Hub\Pool\Poolable;
 
 // Import framework stuff
 use CoreFramework\Factory\ObjectFactory;
@@ -416,8 +417,8 @@ class BaseListener extends BaseHubSystem implements Visitable {
                $currentSocketData = $this->getIteratorInstance()->current();
 
                // Handle it here, if not main server socket
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-LISTENER: currentSocketData=' . $currentSocketData[BasePool::SOCKET_ARRAY_INSTANCE] . ',type=' . $currentSocketData[BasePool::SOCKET_ARRAY_CONN_TYPE] . ',serverSocket=' . $this->getSocketInstance()->getSocketResource());
-               if (($currentSocketData[BasePool::SOCKET_ARRAY_CONN_TYPE] != BaseConnectionHelper::CONNECTION_TYPE_SERVER) && (!$currentSocketData[BasePool::SOCKET_ARRAY_INSTANCE]->equals($this->getSocketInstance()))) {
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-LISTENER: currentSocketData=' . $currentSocketData[Poolable::SOCKET_ARRAY_INSTANCE] . ',type=' . $currentSocketData[Poolable::SOCKET_ARRAY_CONN_TYPE] . ',serverSocket=' . $this->getSocketInstance()->getSocketResource());
+               if (($currentSocketData[Poolable::SOCKET_ARRAY_CONN_TYPE] != BaseConnectionHelper::CONNECTION_TYPE_SERVER) && (!$currentSocketData[Poolable::SOCKET_ARRAY_INSTANCE]->equals($this->getSocketInstance()))) {
                        // ... or else it will raise warnings like 'Transport endpoint is not connected'
                        $this->getHandlerInstance()->processRawDataFromResource($currentSocketData);
                } // END - if
index 3c26b71d19456d4510757de04136fbdcec2c3daf..41584f769776b23f55764db9e050c08088c2f5de 100644 (file)
@@ -3,6 +3,7 @@
 namespace Hub\Network\Package;
 
 // Import application-specific stuff
+use Hub\Container\Socket\StorableSocket;
 use Hub\Factory\Assembler\Package\PackageAssemblerFactory;
 use Hub\Factory\Dht\DhtObjectFactory;
 use Hub\Factory\Information\Connection\ConnectionInfoFactory;
index fc62e814949d78ad015c058978e072c3b2604254..a95573cd7baba8af0a76d6de3ea591ea14f000b1 100644 (file)
@@ -36,12 +36,6 @@ use CoreFramework\Visitor\Visitor;
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 abstract class BasePool extends BaseHubSystem implements Poolable, Visitable {
-       /**
-        * Socket array elements
-        */
-       const SOCKET_ARRAY_INSTANCE  = 'instance';
-       const SOCKET_ARRAY_CONN_TYPE = 'connection_type';
-
        /**
         * A list of pool entries
         */
index 74ec3123ed49eca2a448295bd8f0f4cde0a35484..42f681b72ade4a14551f73fbb48de90e404bd94c 100644 (file)
@@ -8,6 +8,7 @@ use Hub\Listener\Listenable;
 use Hub\Locator\Node\LocateableNode;
 use Hub\Network\Package\NetworkPackage;
 use Hub\Pool\BasePool;
+use Hub\Pool\Poolable;
 use Hub\Pool\Peer\PoolablePeer;
 
 // Import framework stuff
@@ -132,8 +133,8 @@ class DefaultPeerPool extends BasePool implements PoolablePeer {
 
                // Construct the array
                $socketArray = array(
-                       self::SOCKET_ARRAY_INSTANCE  => $socketInstance,
-                       self::SOCKET_ARRAY_CONN_TYPE => $connectionType
+                       Poolable::SOCKET_ARRAY_INSTANCE  => $socketInstance,
+                       Poolable::SOCKET_ARRAY_CONN_TYPE => $connectionType
                );
 
                // Add it finally to the pool
@@ -168,7 +169,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer {
                // "Walk" through all socket arrays
                foreach ($socketArrays as $socketArray) {
                        // Add the socket
-                       array_push($sockets, $socketArray[self::SOCKET_ARRAY_INSTANCE]);
+                       array_push($sockets, $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]);
                } // END - foreach
 
                // Return it
@@ -198,9 +199,9 @@ class DefaultPeerPool extends BasePool implements PoolablePeer {
                // "Walk" through all socket arrays
                foreach ($socketArrays as $socketArray) {
                        // Does it match?
-                       if ($socketArray[self::SOCKET_ARRAY_CONN_TYPE] === $connectionType) {
+                       if ($socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE] === $connectionType) {
                                // Add the socket
-                               array_push($sockets, $socketArray[self::SOCKET_ARRAY_INSTANCE]);
+                               array_push($sockets, $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]);
                        } // END - if
                } // END - foreach
 
@@ -249,9 +250,9 @@ class DefaultPeerPool extends BasePool implements PoolablePeer {
                // Get all sockets and check them, skip the server socket
                foreach ($sockets as $socketArray) {
                        // Is this a server socket?
-                       if ($socketArray[self::SOCKET_ARRAY_INSTANCE]->equals($this->getListenerInstance()->getSocketInstance())) {
+                       if ($socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->equals($this->getListenerInstance()->getSocketInstance())) {
                                // Skip 'server' sockets (local socket)
-                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('POOL: Skipping server socket ' . $socketArray[self::SOCKET_ARRAY_INSTANCE]->getSocketResource() . ' ...');
+                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('POOL: Skipping server socket ' . $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketResource() . ' ...');
                                continue;
                        } // END - if
 
@@ -260,19 +261,19 @@ class DefaultPeerPool extends BasePool implements PoolablePeer {
                        $peerPort    = '0';
 
                        // Try to get the "peer"'s name
-                       if (!$socketArray[self::SOCKET_ARRAY_INSTANCE]->getSocketPeerName($peerAddress, $peerPort)) {
+                       if (!$socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketPeerName($peerAddress, $peerPort)) {
                                // Handle the socket error with given package data
-                               $socketArray[self::SOCKET_ARRAY_INSTANCE]->handleSocketError(__METHOD__, __LINE__, explode(':', $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
+                               $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->handleSocketError(__METHOD__, __LINE__, explode(':', $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
                        } // END - if
 
                        // Get
                        // If the "peer" IP and recipient is same, use it
                        if ($peerAddress == $unlData[LocateableNode::UNL_PART_ADDRESS]) {
                                // IPs match, so take the socket and quit this loop
-                               $socketInstance = $socketArray[self::SOCKET_ARRAY_INSTANCE];
+                               $socketInstance = $socketArray[Poolable::SOCKET_ARRAY_INSTANCE];
 
                                // Debug message
-                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('POOL: peerAddress=' . $peerAddress . ' matches with recipient IP address. Taking socket=' . $socketArray[self::SOCKET_ARRAY_INSTANCE] . ',type=' . $socketArray[self::SOCKET_ARRAY_CONN_TYPE]);
+                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('POOL: peerAddress=' . $peerAddress . ' matches with recipient IP address. Taking socket=' . $socketArray[Poolable::SOCKET_ARRAY_INSTANCE] . ',type=' . $socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE]);
                                break;
                        } // END - if
                } // END - foreach
index 01ca7cede108fed346887f4345e50b2e4db0b6e0..18699ec3026caa3b0f7d4c3d5fc7c4d9596f42ca 100644 (file)
@@ -41,7 +41,7 @@ use CoreFramework\Registry\Sub\SubRegistry;
  */
 class SocketRegistry extends BaseRegistry implements Register, RegisterableSocket {
        // Exception constants
-       const SOCKET_NOT_REGISTERED = 0xd200;
+       const EXCEPTION_SOCKET_NOT_REGISTERED = 0xd200;
 
        /**
         * Instance of this class
@@ -258,7 +258,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke
                // The socket must be registered before we can return it
                if (!$this->isInfoRegistered($listenerInstance)) {
                        // Throw the exception
-                       throw new NoSocketRegisteredException ($listenerInstance, self::SOCKET_NOT_REGISTERED);
+                       throw new NoSocketRegisteredException ($listenerInstance, self::EXCEPTION_SOCKET_NOT_REGISTERED);
                } // END - if
 
                // Now get the key from the listener
index c3d57988451142aa23acc1e584bf37e2832bc52b..9ba4ce7186031c1c3a2fd4f46c52dd8b3ffd835c 100644 (file)
@@ -82,19 +82,4 @@ interface HubInterface extends FrameworkInterface {
         */
        function getSessionId ();
 
-       /**
-        * Setter for socket instance
-        *
-        * @param       $socketInstance A StorableSocket instance
-        * @return      void
-        */
-       function setSocketInstance (StorableSocket $socketInstance);
-
-       /**
-        * Getter for socket instance
-        *
-        * @return      $socketInstance An instance of a StorableSocket class
-        */
-       function getSocketInstance ();
-
 }
index 5e6c97461fd5c256291ac637fb890a8c8ab3c85b..5d9d17d949f651b6dba91fe390cf3da3720c20cf 100644 (file)
@@ -3,6 +3,7 @@
 namespace Hub\Listener;
 
 // Import application-specific stuff
+use Hub\Container\Socket\StorableSocket;
 use Hub\Generic\HubInterface;
 
 /**
@@ -86,4 +87,19 @@ interface Listenable extends HubInterface {
         */
        function getPoolInstance ();
 
+       /**
+        * Setter for socket instance
+        *
+        * @param       $socketInstance A StorableSocket instance
+        * @return      void
+        */
+       function setSocketInstance (StorableSocket $socketInstance);
+
+       /**
+        * Getter for socket instance
+        *
+        * @return      $socketInstance An instance of a StorableSocket class
+        */
+       function getSocketInstance ();
+
 }
index d48f7cd26f24210c2a864d14b48bfa89e55b8c71..653421a32dbf2989d897f9b02999b73de1b1b89d 100644 (file)
@@ -28,6 +28,11 @@ use Hub\Generic\HubInterface;
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 interface Poolable extends HubInterface {
+       /**
+        * Socket array elements
+        */
+       const SOCKET_ARRAY_INSTANCE  = 'instance';
+       const SOCKET_ARRAY_CONN_TYPE = 'connection_type';
 
        /**
         * Pre-shuts down the pool
diff --git a/core b/core
index ca40302a326b814bbd5273a0540e18d672cf2d70..b89f58d4d90b6d608b8e16b0e5e3235eaff4f54e 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit ca40302a326b814bbd5273a0540e18d672cf2d70
+Subproject commit b89f58d4d90b6d608b8e16b0e5e3235eaff4f54e