From: Roland Häder Date: Sun, 20 May 2012 12:21:34 +0000 (+0000) Subject: Error code 'empty_data' is now fully removed and empty data is being silently ignored... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=cb78f38cf539d77c974470db748db0987092009d;p=hub.git Error code 'empty_data' is now fully removed and empty data is being silently ignored, some noisy lines commented out --- diff --git a/application/hub/main/handler/network/class_BaseRawDataHandler.php b/application/hub/main/handler/network/class_BaseRawDataHandler.php index 1fc3cde76..f29ab1cde 100644 --- a/application/hub/main/handler/network/class_BaseRawDataHandler.php +++ b/application/hub/main/handler/network/class_BaseRawDataHandler.php @@ -26,7 +26,6 @@ class BaseRawDataHandler extends BaseHandler { // - Socket raw data stream errors const SOCKET_ERROR_UNKNOWN = 'unknown_error'; // Unknown error (should not happen) const SOCKET_ERROR_TRANSPORT_ENDPOINT = 'transport_endpoint'; // Transport endpoint has closed - const SOCKET_ERROR_EMPTY_DATA = 'empty_data'; // Other peer has sent nothing const SOCKET_ERROR_INVALID_BASE64_MODULO = 'base64_modulo'; // Length is not modulo 4 const SOCKET_ERROR_INVALID_BASE64_MESSAGE = 'base64_message'; // Raw data is not Base64-encoded const SOCKET_ERROR_UNHANDLED = 'unhandled_package'; // Unhandled raw data (not bad) diff --git a/application/hub/main/handler/network/tcp/class_TcpRawDataHandler.php b/application/hub/main/handler/network/tcp/class_TcpRawDataHandler.php index e71b3f151..f3ecf6105 100644 --- a/application/hub/main/handler/network/tcp/class_TcpRawDataHandler.php +++ b/application/hub/main/handler/network/tcp/class_TcpRawDataHandler.php @@ -69,7 +69,7 @@ class TcpRawDataHandler extends BaseRawDataHandler implements Networkable { $decodedData = false; // Debug message - /* NOISY-DEBUG: */ $this->debugOutput('TCP-HANDLER: Handling TCP package from resource=' . $socketArray[BasePool::SOCKET_ARRAY_RESOURCE] . ',type=' . $socketArray[BasePool::SOCKET_ARRAY_CONN_TYPE] . ',last error=' . socket_strerror(socket_last_error($socketArray[BasePool::SOCKET_ARRAY_RESOURCE]))); + //* NOISY-DEBUG: */ $this->debugOutput('TCP-HANDLER: Handling TCP package from resource=' . $socketArray[BasePool::SOCKET_ARRAY_RESOURCE] . ',type=' . $socketArray[BasePool::SOCKET_ARRAY_CONN_TYPE] . ',last error=' . socket_strerror(socket_last_error($socketArray[BasePool::SOCKET_ARRAY_RESOURCE]))); /* * Read the raw data from socket. If you change PHP_BINARY_READ to @@ -79,12 +79,12 @@ class TcpRawDataHandler extends BaseRawDataHandler implements Networkable { $rawData = socket_read($socketArray[BasePool::SOCKET_ARRAY_RESOURCE], $this->getConfigInstance()->getConfigEntry('tcp_buffer_length'), PHP_BINARY_READ); // Debug output of read data length - /* NOISY-DEBUG: */ $this->debugOutput('TCP-HANDLER: rawData[' . gettype($rawData) . ']=' . strlen($rawData) . ',resource=' . $socketArray[BasePool::SOCKET_ARRAY_RESOURCE] . ',error=' . socket_strerror(socket_last_error($socketArray[BasePool::SOCKET_ARRAY_RESOURCE]))); + //* NOISY-DEBUG: */ $this->debugOutput('TCP-HANDLER: rawData[' . gettype($rawData) . ']=' . strlen($rawData) . ',resource=' . $socketArray[BasePool::SOCKET_ARRAY_RESOURCE] . ',error=' . socket_strerror(socket_last_error($socketArray[BasePool::SOCKET_ARRAY_RESOURCE]))); // Is it valid? if (socket_last_error($socketArray[BasePool::SOCKET_ARRAY_RESOURCE]) == 11) { // Debug message - /* NOISY-DEBUG: */ $this->debugOutput('TCP-HANDLER: Ignoring error 11 (Resource temporary unavailable) from socket resource=' . $socketArray[BasePool::SOCKET_ARRAY_RESOURCE]); + //* NOISY-DEBUG: */ $this->debugOutput('TCP-HANDLER: Ignoring error 11 (Resource temporary unavailable) from socket resource=' . $socketArray[BasePool::SOCKET_ARRAY_RESOURCE]); /* * Error code 11 (Resource temporary unavailable) can be safely @@ -92,12 +92,15 @@ class TcpRawDataHandler extends BaseRawDataHandler implements Networkable { * sending any data. */ socket_clear_error($socketArray[BasePool::SOCKET_ARRAY_RESOURCE]); + + // Skip any further processing + return; } elseif (($rawData === false) || (socket_last_error($socketArray[BasePool::SOCKET_ARRAY_RESOURCE]) > 0)) { // Network error or connection lost $this->setErrorCode(socket_last_error($socketArray[BasePool::SOCKET_ARRAY_RESOURCE])); } elseif (empty($rawData)) { - // The peer did send nothing to us - $this->setErrorCode(self::SOCKET_ERROR_EMPTY_DATA); + // The peer did send nothing to us which is now being ignored + return; } else { /* * Low-level checks of the raw data went all fine, now decode the diff --git a/application/hub/main/listener/tcp/class_TcpListener.php b/application/hub/main/listener/tcp/class_TcpListener.php index c0b98e413..8c8afa890 100644 --- a/application/hub/main/listener/tcp/class_TcpListener.php +++ b/application/hub/main/listener/tcp/class_TcpListener.php @@ -306,14 +306,14 @@ class TcpListener extends BaseListener implements Listenable { // Get the current value $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] . ',serverSocket=' . $this->getSocketResource()); + // Handle it here, if not main server socket + //* 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); } // END - if - // Advance to next entry. This should be the last line + // Advance to next entry. This should be the last line. $this->getIteratorInstance()->next(); } @@ -322,9 +322,11 @@ class TcpListener extends BaseListener implements Listenable { * * @param $packageData Raw package data * @return $accepts Whether this listener does accept + * @throws UnsupportedOperationException If this method is called */ public function ifListenerAcceptsPackageData (array $packageData) { - $this->debugBackTrace('This call should not happen. Please report it.'); + // Please don't call this + throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); } }