diff options
author | Marco van Wieringen <marco.van.wieringen@bareos.com> | 2015-11-19 16:13:14 +0300 |
---|---|---|
committer | Marco van Wieringen <marco.van.wieringen@bareos.com> | 2015-11-19 20:09:36 +0300 |
commit | 27fbfd02ab64d54e92457f0eda6ef2fd60c0cd70 (patch) | |
tree | 2ead85e5a310a790942ec5d8e96f3052a500ef1c | |
parent | b4bd8e2068076070f6523cb5e63f9c3271fa5ec7 (diff) |
Fix fread loop.Release/15.2.2
As fread updates rlen we should set it again to the wanted chunksize in
the next run of the loop. We also check if there are any bytes left to
read if the loop ends that reads things in chunks.
-rw-r--r-- | vendor/Bareos/library/Bareos/BSock/BareosBSock.php | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/vendor/Bareos/library/Bareos/BSock/BareosBSock.php b/vendor/Bareos/library/Bareos/BSock/BareosBSock.php index 443eae1..2cdde04 100644 --- a/vendor/Bareos/library/Bareos/BSock/BareosBSock.php +++ b/vendor/Bareos/library/Bareos/BSock/BareosBSock.php @@ -63,6 +63,8 @@ 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, @@ -275,16 +277,24 @@ class BareosBSock implements BareosBSockInterface $len = self::ntohl($buffer); - if ($len == 0) { + if ($len === 0) { break; } if ($len > 0) { - $rlen = 1024; - while (floor($len / $rlen) > 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; } - $msg .= fread($this->socket, $len); + // Read any remaining bytes + if ($len > 0) { + $msg .= fread($this->socket, $len); + } } elseif ($len < 0) { // signal received switch ($len) { @@ -512,6 +522,7 @@ class BareosBSock implements BareosBSockInterface if (!$this->socket) { throw new \Exception("Error: " . $errstr . ", director seems to be down or blocking our request."); } + // socket_set_nonblock($this->socket); } catch(\Exception $e) { echo $e->getMessage(); |