private function ReadQueueHeader($bLockHeld = false)
 {
     if ($bLockHeld == false) {
         $err = $this->ReadLock();
         if ($err != EOK) {
             return $err;
         }
     }
     //
     // Load the header bytes.
     //
     $headerJson = shmop_read($this->shmHandle, 0, LsShmQueue::HEADER_SIZE);
     if ($headerJson === false) {
         if ($bLockHeld == false) {
             $this->Unlock();
         }
         return EIO;
     }
     //
     // Trim any trailing whitespace since we're reading in a larger block
     // than the structure actually takes up.
     //
     $headerJson = rtrim($headerJson);
     //
     // The first 8 characters are the generation counter.
     //
     $generation = substr($headerJson, LsShmQueue::GENERATION_OFFSET, LsShmQueue::GENERATION_SIZE);
     $this->generation = hexdec($generation);
     //
     // Pull out the record portion of the storage.
     //
     $headerJson = substr($headerJson, LsShmQueue::HEADER_OFFSET);
     //
     // Decode the json structure.
     //
     $headerArray = json_decode($headerJson, true);
     if ($headerArray === null) {
         //
         // This structure isn't valid in shared memory, return ENOENT.
         //
         if ($bLockHeld == false) {
             $this->Unlock();
         }
         return ENOENT;
     }
     //
     // Make sure all the fields exist.
     //
     if (!isset($headerArray['version']) || !isset($headerArray['inPtr']) || !isset($headerArray['outPtr']) || !isset($headerArray['queueDepth']) || !isset($headerArray['shmSize']) || !isset($headerArray['qeSize']) || !isset($headerArray['lockFilename']) || !isset($headerArray['bIsLocking']) || !isset($headerArray['msgMemSize']) || !isset($headerArray['msgMemInPtr']) || !isset($headerArray['msgMemOutPtr']) || !isset($headerArray['crc32'])) {
         if ($bLockHeld == false) {
             $this->Unlock();
         }
         return ENOENT;
     }
     //
     // Compute crc and validate.
     //
     $crcInMemory = $headerArray['crc32'];
     $headerArray['crc32'] = LsShmQueue::BLANK_CRC;
     $json = LsJson::CreateList($headerArray);
     $crcComputed = sprintf("%08X", crc32($json));
     if ($crcInMemory !== $crcComputed) {
         if ($bLockHeld == false) {
             $this->Unlock();
         }
         return EBADCRC;
     }
     //
     // Load the values into the object.
     //
     $this->version = $headerArray['version'];
     $this->inPtr = $headerArray['inPtr'];
     $this->outPtr = $headerArray['outPtr'];
     $this->queueDepth = $headerArray['queueDepth'];
     $this->shmSize = $headerArray['shmSize'];
     $this->qeSize = $headerArray['qeSize'];
     $this->lockFilename = $headerArray['lockFilename'];
     $this->bIsLocking = $headerArray['bIsLocking'];
     $this->msgMemSize = $headerArray['msgMemSize'];
     $this->msgMemInPtr = $headerArray['msgMemInPtr'];
     $this->msgMemOutPtr = $headerArray['msgMemOutPtr'];
     if ($bLockHeld == false) {
         $this->Unlock();
     }
     return EOK;
 }
Exemple #2
0
 public static function CreateList_backup(&$array, $bObjBrackets = true, $bPrettyOutput = false)
 {
     $json = "";
     $bRemoveComma = false;
     if ($bObjBrackets === true) {
         $json .= LsJson::OpenObject($bPrettyOutput);
     }
     //
     // Create the var/value pairs
     //
     foreach ($array as $key => $value) {
         if (is_array($array[$key]) === true) {
             $value = LsJson::CreateList($array[$key], $bObjBrackets, $bPrettyOutput);
         } else {
             if (is_object($array[$key]) === true) {
                 //
                 // Check to see if the ToJson() method exists.
                 //
                 if (method_exists($array[$key], 'ToJson') === true) {
                     $value = $array[$key]->ToJson();
                 }
             }
         }
         $json .= LsJson::VarValue($key, $value, $bPrettyOutput) . ",";
         $bRemoveComma = true;
     }
     if ($bRemoveComma === true) {
         $json = substr($json, 0, -1);
     }
     if ($bObjBrackets === true) {
         $json .= LsJson::CloseObject($bPrettyOutput);
     }
     return $json;
 }