PragmaTwice commented on code in PR #1839:
URL: https://github.com/apache/kvrocks/pull/1839#discussion_r1365777349
##########
src/common/rdb_stream.cc:
##########
@@ -50,20 +50,18 @@ Status RdbFileStream::Open() {
return Status::OK();
}
-StatusOr<size_t> RdbFileStream::Read(char *buf, size_t len) {
- size_t n = 0;
+Status RdbFileStream::Read(char *buf, size_t len) {
while (len) {
size_t read_bytes = std::min(max_read_chunk_size_, len);
ifs_.read(buf, static_cast<std::streamsize>(read_bytes));
if (!ifs_.good()) {
- return Status(Status::NotOK, fmt::format("read failed: {}:",
strerror(errno)));
+ return {Status::NotOK, fmt::format("read failed: {}:", strerror(errno))};
}
check_sum_ = crc64(check_sum_, reinterpret_cast<const unsigned char
*>(buf), read_bytes);
- buf = (char *)buf + read_bytes;
+ buf = buf + read_bytes;
+ DCHECK(len >= read_bytes);
len -= read_bytes;
total_read_bytes_ += read_bytes;
- n += read_bytes;
}
-
- return n;
+ return Status::OK();
Review Comment:
A good change! But I think the real situation can be more complex, e.g. if
eof is reached do we need to use `istream::gcount` to access the real position?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]