]> git.mxchange.org Git - hub.git/commitdiff
Added queue for queued chunks
authorRoland Häder <roland@mxchange.org>
Sun, 17 Apr 2011 22:19:31 +0000 (22:19 +0000)
committerRoland Häder <roland@mxchange.org>
Sun, 17 Apr 2011 22:19:31 +0000 (22:19 +0000)
application/hub/main/helper/connection/class_BaseConnectionHelper.php

index 5ff412c4489bb797de50b62db51ad915bad05206..4771e4d669b0531472f802200c76efaa38760488 100644 (file)
@@ -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);