1
0
Fork 0

Fixed ProtocolStreamWriter for nonblocking connection.

pull/31/head
Stephan Unverwerth 2016-09-29 20:34:45 +02:00
parent 365e128232
commit dbfb7b3912
1 changed files with 11 additions and 1 deletions

View File

@ -25,6 +25,16 @@ class ProtocolStreamWriter implements ProtocolWriter
*/
public function write(Message $msg)
{
fwrite($this->output, (string)$msg);
$data = (string)$msg;
$msgSize = strlen($data);
$totalBytesWritten = 0;
while ($totalBytesWritten < $msgSize) {
$bytesWritten = fwrite($this->output, substr($data, $totalBytesWritten));
if ($bytesWritten === false) {
throw new Error('Could not write message.');
}
$totalBytesWritten += $bytesWritten;
}
}
}