Skip to content
This repository has been archived by the owner on Oct 1, 2023. It is now read-only.

Commit

Permalink
Fix readLineAsync when there is already data available to read
Browse files Browse the repository at this point in the history
  • Loading branch information
fredemmott committed Jun 15, 2018
1 parent 73e4a70 commit b8ac104
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/FileHandleInput.hh
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,19 @@ final class FileHandleInput implements InputInterface {
return '';
}

await $this->waitForDataAsync();
if ($max_bytes === null) {
// PHP does not document the default value
$data = \fgets($this->f);
$impl = () ==> \fgets($this->f);
} else {
// However, it does document that up to `$length - 1` bytes are returned
$data = \fgets($this->f, $max_bytes + 1);
$impl = () ==> \fgets($this->f, $max_bytes + 1);
}
$data = $impl();
if ($data === false) {
return '';
await $this->waitForDataAsync();
$data = $impl();
}
return $data;
return $data === false ? '' : $data;
}

/**
Expand Down

0 comments on commit b8ac104

Please sign in to comment.