From 90b5ae801b9a14d35fb52a6559184d72b5f482aa Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 19 May 2012 17:10:27 +0000 Subject: [PATCH] Removed generic array handling, always have special arrays. Added verification of connection type to getSocketsByConnectionType() --- .../hub/interfaces/pool/peer/class_PoolablePeer.php | 1 + application/hub/main/listener/tcp/class_TcpListener.php | 8 ++++---- application/hub/main/lists/class_BaseList.php | 3 --- application/hub/main/pools/peer/class_DefaultPeerPool.php | 7 +++++++ 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/application/hub/interfaces/pool/peer/class_PoolablePeer.php b/application/hub/interfaces/pool/peer/class_PoolablePeer.php index ad81095c2..6c89ca804 100644 --- a/application/hub/interfaces/pool/peer/class_PoolablePeer.php +++ b/application/hub/interfaces/pool/peer/class_PoolablePeer.php @@ -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); } diff --git a/application/hub/main/listener/tcp/class_TcpListener.php b/application/hub/main/listener/tcp/class_TcpListener.php index 8d0a97596..44313664a 100644 --- a/application/hub/main/listener/tcp/class_TcpListener.php +++ b/application/hub/main/listener/tcp/class_TcpListener.php @@ -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); diff --git a/application/hub/main/lists/class_BaseList.php b/application/hub/main/lists/class_BaseList.php index 7fe351e45..4def45ba5 100644 --- a/application/hub/main/lists/class_BaseList.php +++ b/application/hub/main/lists/class_BaseList.php @@ -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.'); diff --git a/application/hub/main/pools/peer/class_DefaultPeerPool.php b/application/hub/main/pools/peer/class_DefaultPeerPool.php index 42fc143a6..7e4efe535 100644 --- a/application/hub/main/pools/peer/class_DefaultPeerPool.php +++ b/application/hub/main/pools/peer/class_DefaultPeerPool.php @@ -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'); -- 2.39.5