Commit 55258846 authored by mku's avatar mku

ZP-150 #comment added streampad to stringstreamwrapper #time 5m

git-svn-id: https://z-push.org/svn/z-push/trunk@1386 b7dd7b3b-3a3c-0410-9da9-bee62a6cc5b5
parent b0d42082
......@@ -48,6 +48,7 @@ class StringStreamWrapper {
private $stringstream;
private $position;
private $stringlength;
private $streampad = 0; // pad stream with 0 string for stream converter (streamlength must be multiple of 4)
/**
* Opens the stream
......@@ -73,6 +74,11 @@ class StringStreamWrapper {
$this->stringstream = $contextOptions[self::PROTOCOL]['string'];
$this->stringlength = strlen($this->stringstream);
// pad the stream to the multiple of 4
if ($this->stringlength % 4 != 0 )
$this->streampad = $this->stringlength + 4 - ($this->stringlength % 4);
ZLog::Write(LOGLEVEL_DEBUG, sprintf("StringStreamWrapper::stream_open(): initialized stream length: %d", $this->stringlength));
return true;
......@@ -89,6 +95,8 @@ class StringStreamWrapper {
public function stream_read($len) {
$data = substr($this->stringstream, $this->position, $len);
$this->position += strlen($data);
if ($this->position == $this->stringlength && $this->streampad != 0 )
$data = str_pad($data, $this->streampad, 0x0);
return $data;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment