Commit d9919210 authored by Kenton Varda's avatar Kenton Varda

Add default implementation for 3-arg AsyncInputStream::read().

The implementation used by AsyncStreamFd was simply calling the general tryRead(), so why not?
parent 2b8cde72
...@@ -115,17 +115,6 @@ public: ...@@ -115,17 +115,6 @@ public:
observer(eventPort, fd, UnixEventPort::FdObserver::OBSERVE_READ_WRITE) {} observer(eventPort, fd, UnixEventPort::FdObserver::OBSERVE_READ_WRITE) {}
virtual ~AsyncStreamFd() noexcept(false) {} virtual ~AsyncStreamFd() noexcept(false) {}
Promise<size_t> read(void* buffer, size_t minBytes, size_t maxBytes) override {
return tryReadInternal(buffer, minBytes, maxBytes, 0).then([=](size_t result) {
KJ_REQUIRE(result >= minBytes, "Premature EOF") {
// Pretend we read zeros from the input.
memset(reinterpret_cast<byte*>(buffer) + result, 0, minBytes - result);
return minBytes;
}
return result;
});
}
Promise<size_t> tryRead(void* buffer, size_t minBytes, size_t maxBytes) override { Promise<size_t> tryRead(void* buffer, size_t minBytes, size_t maxBytes) override {
return tryReadInternal(buffer, minBytes, maxBytes, 0); return tryReadInternal(buffer, minBytes, maxBytes, 0);
} }
...@@ -1353,6 +1342,16 @@ private: ...@@ -1353,6 +1342,16 @@ private:
Promise<void> AsyncInputStream::read(void* buffer, size_t bytes) { Promise<void> AsyncInputStream::read(void* buffer, size_t bytes) {
return read(buffer, bytes, bytes).then([](size_t) {}); return read(buffer, bytes, bytes).then([](size_t) {});
} }
Promise<size_t> AsyncInputStream::read(void* buffer, size_t minBytes, size_t maxBytes) {
return tryRead(buffer, minBytes, maxBytes).then([=](size_t result) {
KJ_REQUIRE(result >= minBytes, "Premature EOF") {
// Pretend we read zeros from the input.
memset(reinterpret_cast<byte*>(buffer) + result, 0, minBytes - result);
return minBytes;
}
return result;
});
}
void AsyncIoStream::getsockopt(int level, int option, void* value, uint* length) { void AsyncIoStream::getsockopt(int level, int option, void* value, uint* length) {
KJ_UNIMPLEMENTED("Not a socket."); KJ_UNIMPLEMENTED("Not a socket.");
......
...@@ -45,7 +45,7 @@ class AsyncInputStream { ...@@ -45,7 +45,7 @@ class AsyncInputStream {
// Asynchronous equivalent of InputStream (from io.h). // Asynchronous equivalent of InputStream (from io.h).
public: public:
virtual Promise<size_t> read(void* buffer, size_t minBytes, size_t maxBytes) = 0; virtual Promise<size_t> read(void* buffer, size_t minBytes, size_t maxBytes);
virtual Promise<size_t> tryRead(void* buffer, size_t minBytes, size_t maxBytes) = 0; virtual Promise<size_t> tryRead(void* buffer, size_t minBytes, size_t maxBytes) = 0;
Promise<void> read(void* buffer, size_t bytes); Promise<void> read(void* buffer, size_t bytes);
......
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