public function LoadFromMemory() { echo "Loading from memory!!\n"; if ($this->bIsLoaded == true) { return EOK; } if ($this->lockFd == -1 || $this->shmHandle == -1) { return EPERM; } if ($this->qeSize == -1) { return EPERM; } // // Read in the queue header structure. // $err = $this->WriteLock(); $err = $this->ReadQueueHeader(true); if ($err != EOK) { // // Check for no-entry or bad crc and if // we get those errors, rewrite the blank header. // if ($err == ENOENT || $err == EBADCRC) { $err = $this->WriteQueueHeader(true); if ($err != EOK) { LsLogError('Failure to write new queue header'); } } if ($err == EOK) { $this->bIsLoaded = true; } $this->Unlock(); return $err; } // // Unlock and flag as loaded. // $this->Unlock(); $this->bIsLoaded = true; // // If the record exists in memory, we want to force our generation // to be out of sync with the current generation to make any // work get picked up if in polling mode. // $this->generation = ($this->generation - 1) % hexdec(0xffffff); print_r($this); return EOK; }
public function WriteBytes($buffer, $numBytes = 0) { // // Issue the write and override the write block size if the caller // sets a non-zero value. // if ($numBytes === 0) { $numBytes = min($this->writeBlockSize, strlen($buffer)); } $this->WriteInit(strlen($buffer)); $bytesWritten = @fwrite($this->conn, $buffer, $numBytes); if ($bytesWritten === false) { $this->WriteSetForContiuation($buffer); LsLogInfo(LsSys::LS_LOG_SERVER, "Write returned false for {$numBytes} bytes to IP=" . $this->peerIp . " Returning ECONTIO"); return EIO; } // // We need to ensure this buffer is flushed because we can // easily overrun the tcp connection and that seems to cause // big problems for php socket streams... // $err = $this->FlushConnection(); if ($err != EOK) { $this->WriteSetForContiuation($buffer); LsLogError(LsSys::LS_LOG_SERVER, "Write[" . $this->writeOpCount . "]=" . $bytesWritten . " Flush Failed! for " . $this->bytesWritten . "/" . $this->bytesToWrite . " bytes to IP=" . $this->peerIp . " Returning err=ECONTIO"); return EIO; } $this->WriteAdvance($bytesWritten); // // If we weren't able to write everything, then cache the buffer // and return continue i/o status. // if ($this->WriteComplete() == false) { $this->WriteSetForContiuation($buffer, $bytesWritten); LsLogDebug(LsSys::LS_LOG_SERVER, "Write[" . $this->writeOpCount . "]=" . $bytesWritten . " Needs Continuation " . $this->bytesWritten . "/" . $this->bytesToWrite . " bytes to IP=" . $this->peerIp . " Returning ECONTIO"); return ECONTIO; } LsLogDebug(LsSys::LS_LOG_SERVER, "Write[" . $this->writeOpCount . "]=" . $bytesWritten . " Complete " . $this->bytesWritten . "/" . $this->bytesToWrite . " bytes to IP=" . $this->peerIp . " Returning err=EOK"); return EOK; }