From: Roland Häder Date: Sun, 17 Apr 2011 22:19:31 +0000 (+0000) Subject: Added queue for queued chunks X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=87e41bdad425088c7e85bdef0679283e90694fca;p=hub.git Added queue for queued chunks --- diff --git a/application/hub/main/helper/connection/class_BaseConnectionHelper.php b/application/hub/main/helper/connection/class_BaseConnectionHelper.php index 5ff412c44..4771e4d66 100644 --- a/application/hub/main/helper/connection/class_BaseConnectionHelper.php +++ b/application/hub/main/helper/connection/class_BaseConnectionHelper.php @@ -58,9 +58,9 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc private $shuttedDown = false; /** - * Currently sent chunks + * Currently queued chunks */ - private $sentChunks = array(); + private $queuedChunks = array(); /** * Current final hash @@ -151,7 +151,7 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc * 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? @@ -172,8 +172,15 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc // 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]; } /** @@ -196,7 +203,7 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc */ 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(); @@ -217,7 +224,10 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc // 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);