in src/io/BufferedReader.php [211:249]
public async function readFixedSizeAsync(
int $size,
?int $timeout_ns = null,
): Awaitable<string> {
$timer = new \HH\Lib\_Private\OptionalIncrementalTimeout(
$timeout_ns,
() ==> {
_OS\throw_errno(
OS\Errno::ETIMEDOUT,
"Reached timeout before reading requested amount of data",
);
},
);
while (Str\length($this->buffer) < $size && !$this->eof) {
await $this->fillBufferAsync(
$size - Str\length($this->buffer),
$timer->getRemainingNS(),
);
}
if ($this->eof) {
throw new OS\BrokenPipeException(
OS\Errno::EPIPE,
'Reached end of file before requested size',
);
}
$buffer_size = Str\length($this->buffer);
invariant(
$buffer_size >= $size,
"Should have read the requested data or reached EOF",
);
if ($size === $buffer_size) {
$ret = $this->buffer;
$this->buffer = '';
return $ret;
}
$ret = Str\slice($this->buffer, 0, $size);
$this->buffer = Str\slice($this->buffer, $size);
return $ret;
}