private $shuttedDown = false;
/**
- * Currently sent chunks
+ * Currently queued chunks
*/
- private $sentChunks = array();
+ private $queuedChunks = array();
/**
* Current final hash
* 4) Finally return the chunk (array) to the caller
*
* @param $packageData Raw package data array
- * @return $rawDataChunk An array with the raw data as value and chunk hash as key
+ * @return $chunkData Raw data chunk
*/
private function getRawDataFromPackageArray (array $packageData) {
// If there is no fragmenter?
// Get the next raw data chunk from the fragmenter
$rawDataChunk = $fragmenterInstance->getNextRawDataChunk($this->currentFinalHash);
- // Return it
- return $rawDataChunk;
+ // Get chunk hashes and chunk data
+ $chunkHashes = array_keys($rawDataChunk);
+ $chunkData = array_values($rawDataChunk);
+
+ // Remember this chunk as queued
+ $this->queuedChunks[$chunkHashes[0]] = $chunkData[0];
+
+ // Return the raw data
+ return $chunkData[0];
}
/**
*/
public function sendRawPackageData (array $packageData) {
// Convert the package data array to a raw data stream
- $rawDataChunk = $this->getRawDataFromPackageArray($packageData);
+ $rawData = $this->getRawDataFromPackageArray($packageData);
// Get socket resource
$socketResource = $this->getSocketResource();
// And throw it
throw new InvalidSocketException(array($this, gettype($socketResource), $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
- } // END - if
+ } elseif ($sentBytes == 0) {
+ // Nothing sent is bad news
+ die(__METHOD__.': Unhandled 0 sent bytes! rawData[]=' . strlen($rawData));
+ }
// The difference between sent bytes and length of raw data should not be below zero
assert((strlen($rawData) - $sentBytes) >= 0);