Handle closed input or output stream (#110)
parent
a19d225a7a
commit
83afa0c1b8
|
@ -6,6 +6,7 @@ namespace LanguageServer;
|
||||||
use LanguageServer\Protocol\Message;
|
use LanguageServer\Protocol\Message;
|
||||||
use AdvancedJsonRpc\Message as MessageBody;
|
use AdvancedJsonRpc\Message as MessageBody;
|
||||||
use Sabre\Event\Loop;
|
use Sabre\Event\Loop;
|
||||||
|
use RuntimeException;
|
||||||
|
|
||||||
abstract class ParsingMode
|
abstract class ParsingMode
|
||||||
{
|
{
|
||||||
|
@ -29,6 +30,10 @@ class ProtocolStreamReader implements ProtocolReader
|
||||||
{
|
{
|
||||||
$this->input = $input;
|
$this->input = $input;
|
||||||
Loop\addReadStream($this->input, function() {
|
Loop\addReadStream($this->input, function() {
|
||||||
|
if (feof($this->input)) {
|
||||||
|
throw new RuntimeException('Stream is closed');
|
||||||
|
}
|
||||||
|
|
||||||
while (($c = fgetc($this->input)) !== false && $c !== '') {
|
while (($c = fgetc($this->input)) !== false && $c !== '') {
|
||||||
$this->buffer .= $c;
|
$this->buffer .= $c;
|
||||||
switch ($this->parsingMode) {
|
switch ($this->parsingMode) {
|
||||||
|
|
|
@ -4,7 +4,6 @@ declare(strict_types = 1);
|
||||||
namespace LanguageServer;
|
namespace LanguageServer;
|
||||||
|
|
||||||
use LanguageServer\Protocol\Message;
|
use LanguageServer\Protocol\Message;
|
||||||
use RuntimeException;
|
|
||||||
|
|
||||||
class ProtocolStreamWriter implements ProtocolWriter
|
class ProtocolStreamWriter implements ProtocolWriter
|
||||||
{
|
{
|
||||||
|
@ -31,16 +30,7 @@ class ProtocolStreamWriter implements ProtocolWriter
|
||||||
$totalBytesWritten = 0;
|
$totalBytesWritten = 0;
|
||||||
|
|
||||||
while ($totalBytesWritten < $msgSize) {
|
while ($totalBytesWritten < $msgSize) {
|
||||||
error_clear_last();
|
$bytesWritten = fwrite($this->output, substr($data, $totalBytesWritten));
|
||||||
$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');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$totalBytesWritten += $bytesWritten;
|
$totalBytesWritten += $bytesWritten;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue