From 0c0af54da337c11b01ff5799ab24e54cd6a93e8b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 10 Feb 2012 19:37:47 +0000 Subject: [PATCH] all socketErrorFooHandler() methods shall be protected, else they can't be called (but detected by method_exists()); moved socket_set_nonblock() call above socket_connect() --- .../connection/class_BaseConnectionHelper.php | 2 +- .../tcp/class_TcpConnectionHelper.php | 24 +++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/application/hub/main/helper/connection/class_BaseConnectionHelper.php b/application/hub/main/helper/connection/class_BaseConnectionHelper.php index d7ad4ee35..e2b2dd171 100644 --- a/application/hub/main/helper/connection/class_BaseConnectionHelper.php +++ b/application/hub/main/helper/connection/class_BaseConnectionHelper.php @@ -365,7 +365,7 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc * @param $socketResource A valid socket resource * @throws SocketConnectionException The connection attempts fails with a time-out */ - private function socketErrorConnectionTimedOutHandler ($socketResource) { + protected function socketErrorConnectionTimedOutHandler ($socketResource) { // Get socket error code for verification $socketError = socket_last_error($socketResource); diff --git a/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php b/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php index 1990ddd9e..d22f150fd 100644 --- a/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php +++ b/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php @@ -55,7 +55,11 @@ class TcpConnectionHelper extends BaseConnectionHelper implements ConnectionHelp // Is the socket resource valid? if (!is_resource($socketResource)) { - // Something bad happened + /* + * Something bad happened, calling handleSocketError() is not + * possible here because that method would throw an + * InvalidSocketException back. + */ throw new SocketCreationException(array($helperInstance, gettype($socketResource)), BaseListener::EXCEPTION_SOCKET_CREATION_FAILED); } // END - if @@ -80,6 +84,15 @@ class TcpConnectionHelper extends BaseConnectionHelper implements ConnectionHelp throw new SocketOptionException(array($helperInstance, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET); } // END - if + // Set socket in non-blocking mode + if (!socket_set_nonblock($socketResource)) { + // Handle this socket error with a faked recipientData array + $helperInstance->handleSocketError($socketResource, array('0.0.0.0', '0')); + + // And throw again + throw new SocketOptionException(array($helperInstance, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET); + } // END - if + // Set the resource $helperInstance->setSocketResource($socketResource); @@ -150,15 +163,6 @@ class TcpConnectionHelper extends BaseConnectionHelper implements ConnectionHelp */ } // END - if - // Set socket in non-blocking mode - if (!socket_set_nonblock($socketResource)) { - // Handle this socket error with a faked recipientData array - $helperInstance->handleSocketError($socketResource, array('0.0.0.0', '0')); - - // And throw again - throw new SocketOptionException(array($helperInstance, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET); - } // END - if - // Connection is fully established here, so change the state PeerStateFactory::createPeerStateInstanceByName('connected', $helperInstance); -- 2.39.5