// Register this connection helper
Registry::getRegistry()->addInstance('connection', $this);
+
+ // Initialize output stream
+ $streamInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_output_stream_class');
+
+ // And add it to this connection helper
+ $this->setOutputStreamInstance($streamInstance);
}
/**
* @return $chunkData Raw data chunk
*/
private function getRawDataFromPackageArray (array $packageData) {
- // If there is no fragmenter?
- if (!Registry::getRegistry()->instanceExists('package_fragmenter')) {
- // Get the fragmenter instance
- $fragmenterInstance = ObjectFactory::createObjectByConfiguredName('package_fragmenter_class');
-
- // Add it to the registry
- Registry::getRegistry()->addInstance('package_fragmenter', $fragmenterInstance);
- } else {
- // Get fragmenter from registry
- $fragmenterInstance = Registry::getRegistry()->getInstance('package_fragmenter');
- }
+ // Get the fragmenter instance
+ $fragmenterInstance = FragmenterFactory::createFragmenterInstance('package_fragmenter_class');
// Implode the package data array and fragement the resulting string, returns the final hash
$finalHash = $fragmenterInstance->fragmentPackageArray($packageData, $this);
$bufferSize = $this->getConfigInstance()->getConfigEntry($this->getProtocol() . '_buffer_length');
// Init variables
- $rawData = '';
- $dataStream = ' ';
+ $rawData = '';
+ $dataStream = ' ';
$totalSentBytes = 0;
// Fill sending buffer with data
// Nothing to sent is bad news!
assert(strlen($rawData) > 0);
+ // Encode the raw data with our output-stream
+ $encodedData = $this->getOutputStreamInstance()->streamData($rawData);
+
// Calculate difference
- $this->diff = $bufferSize - strlen($rawData);
+ $this->diff = $bufferSize - strlen($encodedData);
// Get socket resource
$socketResource = $this->getSocketResource();
// Deliver all data
while ($sentBytes !== false) {
// And deliver it
- //* NOISY-DEBUG: */ $this->debugOutput('CONNECTION: Sending out ' . strlen($rawData) . ' bytes,bufferSize=' . $bufferSize . ',diff=' . $this->diff);
- $sentBytes = @socket_write($socketResource, $rawData, ($bufferSize - $this->diff));
+ //* NOISY-DEBUG: */ $this->debugOutput('CONNECTION: Sending out ' . strlen($encodedData) . ' bytes,bufferSize=' . $bufferSize . ',diff=' . $this->diff);
+ $sentBytes = @socket_write($socketResource, $encodedData, ($bufferSize - $this->diff));
// If there was an error, we don't continue here
if ($sentBytes === false) {
// And throw it
throw new InvalidSocketException(array($this, gettype($socketResource), $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
- } elseif (($sentBytes == 0) && (strlen($rawData) > 0)) {
+ } elseif (($sentBytes == 0) && (strlen($encodedData) > 0)) {
// Nothing sent means we are done
//* NOISY-DEBUG: */ $this->debugOutput('CONNECTION: All sent! (' . __LINE__ . ')');
break;
}
// The difference between sent bytes and length of raw data should not be below zero
- assert((strlen($rawData) - $sentBytes) >= 0);
+ assert((strlen($encodedData) - $sentBytes) >= 0);
// Add total sent bytes
$totalSentBytes += $sentBytes;
// Cut out the last unsent bytes
- //* NOISY-DEBUG: */ $this->debugOutput('CONNECTION: Sent out ' . $sentBytes . ' of ' . strlen($rawData) . ' bytes ...');
- $rawData = substr($rawData, $sentBytes);
+ //* NOISY-DEBUG: */ $this->debugOutput('CONNECTION: Sent out ' . $sentBytes . ' of ' . strlen($encodedData) . ' bytes ...');
+ $encodedData = substr($encodedData, $sentBytes);
// Calculate difference again
- $this->diff = $bufferSize - strlen($rawData);
+ $this->diff = $bufferSize - strlen($encodedData);
// Can we abort?
- if (strlen($rawData) <= 0) {
+ if (strlen($encodedData) <= 0) {
// Abort here, all sent!
//* NOISY-DEBUG: */ $this->debugOutput('CONNECTION: All sent! (' . __LINE__ . ')');
break;