]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/pools/client/class_DefaultClientPool.php
Package class renamed, continued (sorry for lame description)
[hub.git] / application / hub / main / pools / client / class_DefaultClientPool.php
index a0ceb977c71301f1177486d4d8d080c61045099b..f8a2338cbab62e44e4fd3e16f6195edcb5bd0f15 100644 (file)
@@ -89,8 +89,26 @@ class DefaultClientPool extends BasePool implements PoolableClient {
                // Validate the socket
                $this->validateSocket($socketResource);
 
+               // Default is this peer's IP
+               $peerName = '0.0.0.0';
+
+               // The socket resource should not match server socket
+               if ($socketResource != $this->getListenerInstance()->getSocketResource()) {
+                       // Try to determine the peer's IP number
+                       if (!socket_getpeername($socketResource, $peerName)) {
+                               // Get last error
+                               $lastError = socket_last_error($socketResource);
+
+                               // Doesn't work!
+                               throw new InvalidSocketException(array($this, gettype($socketResource), $lastError, socket_strerror($lastError)), BaseListener::EXCEPTION_INVALID_SOCKET);
+                       } // END - if
+               } else {
+                       // Server sockets won't work with socket_getpeername()
+                       $this->debugOutput('POOL: Socket resource is server socket. This is no bug.');
+               }
+
                // Output error message
-               $this->debugOutput('POOL: Adding client ' . $socketResource);
+               $this->debugOutput('POOL: Adding client ' . $peerName);
 
                // Add it finally to the pool
                $this->addPoolEntry($socketResource);