From 590bc8e1ffdbe185cb6b8085441bf2ae49b7b1ba Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 19 May 2017 20:57:19 +0200 Subject: [PATCH] Opps, not moved back from core (was not generic because of ConnectionHelper) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../hub/classes/class_BaseHubSystem.ph | 73 ------------------- .../hub/classes/class_BaseHubSystem.php | 73 +++++++++++++++++++ 2 files changed, 73 insertions(+), 73 deletions(-) delete mode 100644 application/hub/classes/class_BaseHubSystem.ph diff --git a/application/hub/classes/class_BaseHubSystem.ph b/application/hub/classes/class_BaseHubSystem.ph deleted file mode 100644 index 7c8c467e0..000000000 --- a/application/hub/classes/class_BaseHubSystem.ph +++ /dev/null @@ -1,73 +0,0 @@ -use Hub\Listener\BaseListener; - -use CoreFramework\Listener\Listenable; - - /** - * Listener instance - */ - private $listenerInstance = NULL; - - /** - * Setter for listener instance - * - * @param $listenerInstance A Listenable instance - * @return void - */ - protected final function setListenerInstance (Listenable $listenerInstance) { - $this->listenerInstance = $listenerInstance; - } - - /** - * Getter for listener instance - * - * @return $listenerInstance A Listenable instance - */ - protected final function getListenerInstance () { - return $this->listenerInstance; - } - - /** - * Handles socket error for given socket resource and peer data. This method - * validates $socketResource if it is a valid resource (see is_resource()) - * but assumes valid data in array $recipientData, except that - * count($recipientData) is always 2. - * - * @param $method Value of __METHOD__ from calling method - * @param $line Value of __LINE__ from calling method - * @param $socketResource A valid socket resource - * @param $socketData A valid socket data array (0 = IP/file name, 1 = port) - * @return void - * @throws InvalidSocketException If $socketResource is no socket resource - * @throws NoSocketErrorDetectedException If socket_last_error() gives zero back - * @todo Move all this socket-related stuff into own class, most of it resides in BaseListener - */ - protected final function handleSocketError ($method, $line, $socketResource, array $socketData) { - // This method handles only socket resources - if (!is_resource($socketResource)) { - // No resource, abort here - throw new InvalidSocketException(array($this, $socketResource), BaseListener::EXCEPTION_INVALID_SOCKET); - } // END - if - - // Check socket array, 1st element is mostly IP address (or file name), 2nd is port number - //* DEBUG-DIE: */ die(__METHOD__ . ':socketData=' . print_r($socketData, true)); - assert(isset($socketData[0])); - assert(isset($socketData[1])); - - // Get error code for first validation (0 is not an error) - $errorCode = socket_last_error($socketResource); - - // If the error code is zero, someone called this method without an error - if ($errorCode == 0) { - // No error detected (or previously cleared outside this method) - throw new NoSocketErrorDetectedException(array($this, $socketResource), BaseListener::EXCEPTION_NO_SOCKET_ERROR); - } // END - if - - // Get handler (method) name - $handlerName = $this->getSocketErrorHandlerFromCode($errorCode); - - // Call-back the error handler method - call_user_func_array(array($this, $handlerName), array($socketResource, $socketData)); - - // Finally clear the error because it has been handled - socket_clear_error($socketResource); - } diff --git a/application/hub/classes/class_BaseHubSystem.php b/application/hub/classes/class_BaseHubSystem.php index b00acce39..7154dba7a 100644 --- a/application/hub/classes/class_BaseHubSystem.php +++ b/application/hub/classes/class_BaseHubSystem.php @@ -4,11 +4,13 @@ namespace Hub\Generic; // Import application-specific stuff use Hub\Information\ShareableInfo; +use Hub\Listener\BaseListener; use Hub\Network\Deliver\Deliverable; use Hub\Network\Receive\Receivable; use Hub\Pool\Poolable; // Import framework stuff +use CoreFramework\Listener\Listenable; use CoreFramework\Object\BaseFrameworkSystem; /** @@ -91,6 +93,11 @@ class BaseHubSystem extends BaseFrameworkSystem { */ private $infoInstance = NULL; + /** + * Listener instance + */ + private $listenerInstance = NULL; + /** * Protected constructor * @@ -297,4 +304,70 @@ class BaseHubSystem extends BaseFrameworkSystem { public final function getSessionId () { return $this->getConfigInstance()->getConfigEntry('session_id'); } + + /** + * Setter for listener instance + * + * @param $listenerInstance A Listenable instance + * @return void + */ + protected final function setListenerInstance (Listenable $listenerInstance) { + $this->listenerInstance = $listenerInstance; + } + + /** + * Getter for listener instance + * + * @return $listenerInstance A Listenable instance + */ + protected final function getListenerInstance () { + return $this->listenerInstance; + } + + /** + * Handles socket error for given socket resource and peer data. This method + * validates $socketResource if it is a valid resource (see is_resource()) + * but assumes valid data in array $recipientData, except that + * count($recipientData) is always 2. + * + * @param $method Value of __METHOD__ from calling method + * @param $line Value of __LINE__ from calling method + * @param $socketResource A valid socket resource + * @param $socketData A valid socket data array (0 = IP/file name, 1 = port) + * @return void + * @throws InvalidSocketException If $socketResource is no socket resource + * @throws NoSocketErrorDetectedException If socket_last_error() gives zero back + * @todo Move all this socket-related stuff into own class, most of it resides in BaseListener + */ + protected final function handleSocketError ($method, $line, $socketResource, array $socketData) { + // This method handles only socket resources + if (!is_resource($socketResource)) { + // No resource, abort here + throw new InvalidSocketException(array($this, $socketResource), BaseListener::EXCEPTION_INVALID_SOCKET); + } // END - if + + // Check socket array, 1st element is mostly IP address (or file name), 2nd is port number + //* DEBUG-DIE: */ die(__METHOD__ . ':socketData=' . print_r($socketData, true)); + assert(isset($socketData[0])); + assert(isset($socketData[1])); + + // Get error code for first validation (0 is not an error) + $errorCode = socket_last_error($socketResource); + + // If the error code is zero, someone called this method without an error + if ($errorCode == 0) { + // No error detected (or previously cleared outside this method) + throw new NoSocketErrorDetectedException(array($this, $socketResource), BaseListener::EXCEPTION_NO_SOCKET_ERROR); + } // END - if + + // Get handler (method) name + $handlerName = $this->getSocketErrorHandlerFromCode($errorCode); + + // Call-back the error handler method + call_user_func_array(array($this, $handlerName), array($socketResource, $socketData)); + + // Finally clear the error because it has been handled + socket_clear_error($socketResource); + } + } -- 2.39.5