1
0
Fork 0

Exit process if input or output stream is broken

pull/110/head
Kaloyan Raev 2016-10-24 13:28:56 +03:00
parent a19d225a7a
commit 2c1d65db68
2 changed files with 5 additions and 10 deletions

View File

@ -29,6 +29,10 @@ class ProtocolStreamReader implements ProtocolReader
{
$this->input = $input;
Loop\addReadStream($this->input, function() {
if (feof($this->input)) {
die;
}
while (($c = fgetc($this->input)) !== false && $c !== '') {
$this->buffer .= $c;
switch ($this->parsingMode) {

View File

@ -31,16 +31,7 @@ class ProtocolStreamWriter implements ProtocolWriter
$totalBytesWritten = 0;
while ($totalBytesWritten < $msgSize) {
error_clear_last();
$bytesWritten = @fwrite($this->output, substr($data, $totalBytesWritten));
if ($bytesWritten === false) {
$error = error_get_last();
if ($error !== null) {
throw new RuntimeException('Could not write message: ' . error_get_last()['message']);
} else {
throw new RuntimeException('Could not write message');
}
}
$bytesWritten = fwrite($this->output, substr($data, $totalBytesWritten));
$totalBytesWritten += $bytesWritten;
}
}