1
0
Fork 0

Merged changes from master

pull/112/head
Stephan Unverwerth 2016-10-24 23:50:27 +02:00
commit 7bb4c47d31
2 changed files with 12 additions and 7 deletions

View File

@ -6,7 +6,6 @@ namespace LanguageServer;
use LanguageServer\Protocol\Message;
use AdvancedJsonRpc\Message as MessageBody;
use Sabre\Event\Loop;
use RuntimeException;
class ProtocolStreamReader implements ProtocolReader
{
@ -26,11 +25,8 @@ class ProtocolStreamReader implements ProtocolReader
public function __construct($input)
{
$this->input = $input;
Loop\addReadStream($this->input, function () {
if (feof($this->input)) {
throw new RuntimeException('Stream is closed');
}
Loop\addReadStream($this->input, function () {
while (($c = fgetc($this->input)) !== false && $c !== '') {
$this->buffer .= $c;
switch ($this->parsingMode) {

View File

@ -5,6 +5,7 @@ namespace LanguageServer;
use LanguageServer\Protocol\Message;
use Sabre\Event\Loop;
use RuntimeException;
class ProtocolStreamWriter implements ProtocolWriter
{
@ -22,9 +23,17 @@ class ProtocolStreamWriter implements ProtocolWriter
{
$this->output = $output;
Loop\addWriteStream($this->output, function () {
$msgSize = strlen($this->buffer);
error_clear_last();
$bytesWritten = @fwrite($this->output, $this->buffer);
if ($bytesWritten > 0) {
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');
}
}
else if ($bytesWritten > 0) {
$this->buffer = substr($this->buffer, $bytesWritten);
}
});