// - 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)
$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
$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
* 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
// 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();
}
*
* @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);
}
}