Skip to content

Commit

Permalink
Switch to stream_get_contents() without CHUNKS
Browse files Browse the repository at this point in the history
We had some problems with bigger chunsizes, but by using
stream_get_contents() everywhere, we could also get rid of reading in
chnks at all.
  • Loading branch information
pstorz committed Nov 23, 2015
1 parent 27fbfd0 commit 9a69ef2
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions vendor/Bareos/library/Bareos/BSock/BareosBSock.php
Expand Up @@ -63,8 +63,6 @@ class BareosBSock implements BareosBSockInterface
const DIR_OK_AUTH = "1000 OK auth\n";
const DIR_AUTH_FAILED = "1999 Authorization failed.\n";

const CHUNK_SIZE = 64;

protected $config = array(
'debug' => false,
'host' => null,
Expand Down Expand Up @@ -241,7 +239,7 @@ private function receive($len=0)
$msg_len = 0;

if ($len === 0) {
$buffer = fread($this->socket, 4);
$buffer = stream_get_contents($this->socket, 4);
if($buffer == false){
return false;
}
Expand All @@ -251,7 +249,7 @@ private function receive($len=0)
}

if ($msg_len > 0) {
$buffer = fread($this->socket, $msg_len);
$buffer = stream_get_contents($this->socket, $msg_len);
}

return $buffer;
Expand All @@ -269,7 +267,7 @@ private function receive_message()
$buffer = "";

while (true) {
$buffer = fread($this->socket, 4);
$buffer = stream_get_contents($this->socket, 4);

if ($buffer === false) {
throw new \Exception("Error reading socket. " . socket_strerror(socket_last_error()) . "\n");
Expand All @@ -281,20 +279,7 @@ private function receive_message()
break;
}
if ($len > 0) {
// Read data in chunks of CHUNK_SIZE
while (floor($len / self::CHUNK_SIZE) > 0) {
$rlen = self::CHUNK_SIZE;
$msg .= fread($this->socket, $rlen);
if ($rlen < 0) {
$len = $rlen;
break;
}
$len -= $rlen;
}
// Read any remaining bytes
if ($len > 0) {
$msg .= fread($this->socket, $len);
}
$msg .= stream_get_contents($this->socket, $len);
} elseif ($len < 0) {
// signal received
switch ($len) {
Expand Down

0 comments on commit 9a69ef2

Please sign in to comment.