Unverified Commit d6c01a0f authored by Kenton Varda's avatar Kenton Varda Committed by GitHub

Merge pull request #620 from capnproto/premature-eof-disconnect

Treat 'Premature EOF' error on async stream as DISCONNECTED.
parents e49e6e60 fe3e3657
...@@ -53,12 +53,14 @@ Promise<void> AsyncInputStream::read(void* buffer, size_t bytes) { ...@@ -53,12 +53,14 @@ Promise<void> AsyncInputStream::read(void* buffer, size_t bytes) {
Promise<size_t> AsyncInputStream::read(void* buffer, size_t minBytes, size_t maxBytes) { Promise<size_t> AsyncInputStream::read(void* buffer, size_t minBytes, size_t maxBytes) {
return tryRead(buffer, minBytes, maxBytes).then([=](size_t result) { return tryRead(buffer, minBytes, maxBytes).then([=](size_t result) {
KJ_REQUIRE(result >= minBytes, "Premature EOF") { if (result >= minBytes) {
return result;
} else {
kj::throwRecoverableException(KJ_EXCEPTION(DISCONNECTED, "stream disconnected prematurely"));
// Pretend we read zeros from the input. // Pretend we read zeros from the input.
memset(reinterpret_cast<byte*>(buffer) + result, 0, minBytes - result); memset(reinterpret_cast<byte*>(buffer) + result, 0, minBytes - result);
return minBytes; return minBytes;
} }
return result;
}); });
} }
......
...@@ -54,7 +54,9 @@ Promise<size_t> GzipAsyncInputStream::readImpl( ...@@ -54,7 +54,9 @@ Promise<size_t> GzipAsyncInputStream::readImpl(
return inner.tryRead(buffer, 1, sizeof(buffer)) return inner.tryRead(buffer, 1, sizeof(buffer))
.then([this,out,minBytes,maxBytes,alreadyRead](size_t amount) -> Promise<size_t> { .then([this,out,minBytes,maxBytes,alreadyRead](size_t amount) -> Promise<size_t> {
if (amount == 0) { if (amount == 0) {
KJ_REQUIRE(atValidEndpoint, "gzip compressed stream ended prematurely"); if (!atValidEndpoint) {
return KJ_EXCEPTION(DISCONNECTED, "gzip compressed stream ended prematurely");
}
return alreadyRead; return alreadyRead;
} else { } else {
ctx.next_in = buffer; ctx.next_in = buffer;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment