X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=application%2Fhub%2Fmain%2Fpools%2Fclient%2Fclass_DefaultClientPool.php;h=f8a2338cbab62e44e4fd3e16f6195edcb5bd0f15;hb=3354cef4df30f6b239c92ec1bda67e5125ae5849;hp=a0ceb977c71301f1177486d4d8d080c61045099b;hpb=cacbd34c6805904991845e9e15de907f22329641;p=hub.git diff --git a/application/hub/main/pools/client/class_DefaultClientPool.php b/application/hub/main/pools/client/class_DefaultClientPool.php index a0ceb977c..f8a2338cb 100644 --- a/application/hub/main/pools/client/class_DefaultClientPool.php +++ b/application/hub/main/pools/client/class_DefaultClientPool.php @@ -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);