]> git.mxchange.org Git - hub.git/commitdiff
Removed generic array handling, always have special arrays. Added verification of...
authorRoland Häder <roland@mxchange.org>
Sat, 19 May 2012 17:10:27 +0000 (17:10 +0000)
committerRoland Häder <roland@mxchange.org>
Sat, 19 May 2012 17:10:27 +0000 (17:10 +0000)
application/hub/interfaces/pool/peer/class_PoolablePeer.php
application/hub/main/listener/tcp/class_TcpListener.php
application/hub/main/lists/class_BaseList.php
application/hub/main/pools/peer/class_DefaultPeerPool.php

index ad81095c2fde718669b4955c09358714e39acfd8..6c89ca8044881d077c20aebf8615e764e1a406a6 100644 (file)
@@ -52,6 +52,7 @@ interface PoolablePeer extends Poolable, SocketTag {
         *
         * @param       $connectionType         Type of connection, can only be 'incoming', 'outgoing' or 'server'
         * @return      $sockets                        An array with sockets of given type
+        * @throws      InvalidConnectionTypeException  If the provided connection type is not valid
         */
        function getSocketsByConnectionType ($connectionType);
 }
index 8d0a97596260c1d3d2507a0ccaa367eaea9ccebc..44313664af5e1a1fb4e1dfc15fc24f169e1d1973 100644 (file)
@@ -217,14 +217,14 @@ class TcpListener extends BaseListener implements Listenable {
                // Some new peers found?
                if ($left < 1) {
                        // Debug message
-                       //* EXTREME-NOISY-DEBUG: */ $this->debugOutput('TCP-LISTENER: left=' . $left . ',server=' . $this->getSocketResource() . ',readers=' . print_r($readers, true));
+                       //* EXTREME-NOISY-DEBUG: */ $this->debugOutput('TCP-LISTENER: left=' . $left . ',serverSocket=' . $this->getSocketResource() . ',readers=' . print_r($readers, true));
 
                        // Nothing new found
                        return;
                } // END - if
 
                // Debug message
-               /* NOISY-DEBUG: */ $this->debugOutput('TCP-LISTENER:server=' . $this->getSocketResource() . ',readers=' . print_r($readers, true));
+               /* NOISY-DEBUG: */ $this->debugOutput('TCP-LISTENER: server=' . $this->getSocketResource() . ',readers=' . print_r($readers, true));
 
                // Do we have changed peers?
                if (in_array($this->getSocketResource(), $readers)) {
@@ -238,7 +238,7 @@ class TcpListener extends BaseListener implements Listenable {
                        $newSocket = socket_accept($this->getSocketResource());
 
                        // Debug message
-                       /* NOISY-DEBUG: */ $this->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: newSocket=' . $newSocket . ',server=' .$this->getSocketResource());
+                       /* NOISY-DEBUG: */ $this->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: newSocket=' . $newSocket . ',serverSocket=' .$this->getSocketResource());
 
                        // Array for timeout settings
                        $options  = array(
@@ -307,7 +307,7 @@ class TcpListener extends BaseListener implements Listenable {
                $currentSocket = $this->getIteratorInstance()->current();
 
                // Handle it here, if not main socket
-               /* NOISY-DEBUG: */ $this->debugOutput('TCP-LISTENER: currentSocket=' . $currentSocket[BasePool::SOCKET_ARRAY_RESOURCE] . ',type=' . $currentSocket[BasePool::SOCKET_ARRAY_CONN_TYPE] . ',server=' . $this->getSocketResource());
+               /* NOISY-DEBUG: */ $this->debugOutput('TCP-LISTENER: currentSocket=' . $currentSocket[BasePool::SOCKET_ARRAY_RESOURCE] . ',type=' . $currentSocket[BasePool::SOCKET_ARRAY_CONN_TYPE] . ',serverSocket=' . $this->getSocketResource());
                if (($currentSocket[BasePool::SOCKET_ARRAY_CONN_TYPE] != BaseConnectionHelper::CONNECTION_TYPE_SERVER) && ($currentSocket[BasePool::SOCKET_ARRAY_RESOURCE] != $this->getSocketResource())) {
                        // ... or else it will raise warnings like 'Transport endpoint is not connected'
                        $this->getHandlerInstance()->processRawDataFromResource($currentSocket);
index 7fe351e4508144a1c862680708f47d0b9d1e833a..4def45ba530257e515d55456a5e2e9cf6302c980 100644 (file)
@@ -269,9 +269,6 @@ class BaseList extends BaseHubSystem implements IteratorAggregate, Countable {
                } elseif ((is_array($entry)) && (isset($entry[BasePool::SOCKET_ARRAY_RESOURCE])) && (isset($entry[BasePool::SOCKET_ARRAY_CONN_TYPE]))) {
                        // Is a socket resource array
                        $entry2 = crc32($entry[BasePool::SOCKET_ARRAY_RESOURCE] . ':' . $entry[BasePool::SOCKET_ARRAY_CONN_TYPE]);
-               } elseif (is_array($entry)) {
-                       // Is a generic array
-                       $entry2 = gettype($entry) . ':' . count($entry);
                } else {
                        // Unsupported type detected
                        $this->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: Entry type ' . gettype($entry) . ' is unsupported.');
index 42fc143a63e52b05020af660575aa5b9d0f7b33a..7e4efe535d74b892900a628382d70e14cb095c4a 100644 (file)
@@ -180,8 +180,15 @@ class DefaultPeerPool extends BasePool implements PoolablePeer {
         *
         * @param       $connectionType         Type of connection, can only be 'incoming', 'outgoing' or 'server'
         * @return      $sockets                        An array with sockets of given type
+        * @throws      InvalidConnectionTypeException  If the provided connection type is not valid
         */
        public function getSocketsByConnectionType ($connectionType) {
+               // Is the connection type valid?
+               if (!$this->isValidConnectionType($connectionType)) {
+                       // Is not a valid connection type!
+                       throw new InvalidConnectionTypeException(array($this, $connectionType), self::EXCEPTION_INVALID_CONNECTION_TYPE);
+               } // END - if
+
                // Get the array list
                $socketArrays = $this->getArrayFromList('pool');