From: Roland Haeder Date: Fri, 14 Mar 2014 20:01:51 +0000 (+0100) Subject: Surpress errors/warnings for socket_write as they flood the later logfiles, added... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=79d4a83018cd932cee912ec0cd907fa703848af1;p=hub.git Surpress errors/warnings for socket_write as they flood the later logfiles, added missing handler method for socket error. Signed-off-by: Roland Haeder --- diff --git a/application/hub/main/handler/network/class_BaseRawDataHandler.php b/application/hub/main/handler/network/class_BaseRawDataHandler.php index 8fcce65fe..93fdb3acf 100644 --- a/application/hub/main/handler/network/class_BaseRawDataHandler.php +++ b/application/hub/main/handler/network/class_BaseRawDataHandler.php @@ -35,7 +35,7 @@ class BaseRawDataHandler extends BaseHandler { const SOCKET_ERROR_OPERATION_ALREADY_PROGRESS = 'operation_already_progress'; // 'Operation already in progress' const SOCKET_ERROR_RESOURCE_UNAVAILABLE = 'resource_unavailable'; // 'Resource temporary unavailable' const SOCKET_ERROR_NO_ROUTE_TO_HOST = 'no_route_to_host'; // The name says it: no route to host - const SOCKET_ERROR_CONNECTION_RESET_BY_PEER = 'reset_by_peer'; // Connection reset by peer + const SOCKET_ERROR_CONNECTION_RESET_BY_PEER = 'connection_reset_by_peer'; // Connection reset by peer const SOCKET_CONNECTED = 'connected'; // Nothing errorous happens, socket is connected // - Package errors diff --git a/application/hub/main/helper/connection/class_BaseConnectionHelper.php b/application/hub/main/helper/connection/class_BaseConnectionHelper.php index b58638b1a..e5abac69c 100644 --- a/application/hub/main/helper/connection/class_BaseConnectionHelper.php +++ b/application/hub/main/helper/connection/class_BaseConnectionHelper.php @@ -584,6 +584,29 @@ class BaseConnectionHelper extends BaseHubSystemHelper implements Registerable, throw new SocketConnectionException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET); } + /** + * Handles socket error 'connection reset by peer', but does not clear it for + * later debugging purposes. + * + * @param $socketResource A valid socket resource + * @param $recipientData An array with two elements: 0=IP number, 1=port number + * @return void + * @throws SocketConnectionException The connection attempts fails with a time-out + */ + protected function socketErrorConnectionResetByPeerHandler ($socketResource, array $recipientData) { + // Get socket error code for verification + $socketError = socket_last_error($socketResource); + + // Get error message + $errorMessage = socket_strerror($socketError); + + // Shutdown this socket + $this->shutdownSocket($socketResource); + + // Throw it again + throw new SocketConnectionException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET); + } + /** * Handles socket "error" 'operation now in progress' which can be safely * passed on with non-blocking connections. diff --git a/application/hub/main/package/class_NetworkPackage.php b/application/hub/main/package/class_NetworkPackage.php index 7e599a416..b1b345928 100644 --- a/application/hub/main/package/class_NetworkPackage.php +++ b/application/hub/main/package/class_NetworkPackage.php @@ -836,11 +836,11 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R if ($encodedDataArray[self::RAW_DIFF_INDEX] >= 0) { // Send all out (encodedData is smaller than or equal buffer size) //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: MD5=' . md5(substr($encodedDataArray[self::RAW_ENCODED_DATA_INDEX], 0, ($encodedDataArray[self::RAW_BUFFER_SIZE_INDEX] - $encodedDataArray[self::RAW_DIFF_INDEX])))); - $sentBytes = socket_write($encodedDataArray[self::RAW_SOCKET_INDEX], $encodedDataArray[self::RAW_ENCODED_DATA_INDEX], ($encodedDataArray[self::RAW_BUFFER_SIZE_INDEX] - $encodedDataArray[self::RAW_DIFF_INDEX])); + $sentBytes = @socket_write($encodedDataArray[self::RAW_SOCKET_INDEX], $encodedDataArray[self::RAW_ENCODED_DATA_INDEX], ($encodedDataArray[self::RAW_BUFFER_SIZE_INDEX] - $encodedDataArray[self::RAW_DIFF_INDEX])); } else { // Send buffer size out //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: MD5=' . md5(substr($encodedDataArray[self::RAW_ENCODED_DATA_INDEX], 0, $encodedDataArray[self::RAW_BUFFER_SIZE_INDEX]))); - $sentBytes = socket_write($encodedDataArray[self::RAW_SOCKET_INDEX], $encodedDataArray[self::RAW_ENCODED_DATA_INDEX], $encodedDataArray[self::RAW_BUFFER_SIZE_INDEX]); + $sentBytes = @socket_write($encodedDataArray[self::RAW_SOCKET_INDEX], $encodedDataArray[self::RAW_ENCODED_DATA_INDEX], $encodedDataArray[self::RAW_BUFFER_SIZE_INDEX]); } // If there was an error, we don't continue here