diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filehandle.cc b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filehandle.cc index df147d3b2bc..40f1b4a957d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filehandle.cc +++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filehandle.cc @@ -78,34 +78,26 @@ Status FileHandleImpl::PositionRead(void *buf, size_t *nbyte, off_t offset) { LOG_TRACE(kFileHandle, << "FileHandleImpl::[sync]PositionRead(" << FMT_THIS_ADDR << ", buf=" << buf << ", nbyte=" << *nbyte << ") called"); - size_t totalBytesRead = 0; - Status stat = Status::OK(); - while (*nbyte != 0 && offset < (off_t)(file_info_->file_length_)) { - auto callstate = std::make_shared>>(); - std::future> future(callstate->get_future()); - /* wrap async call with promise/future to make it blocking */ - auto callback = [callstate](const Status &s, size_t bytes) { - callstate->set_value(std::make_tuple(s,bytes)); - }; + auto callstate = std::make_shared>>(); + std::future> future(callstate->get_future()); - PositionRead(buf, *nbyte, offset, callback); + /* wrap async call with promise/future to make it blocking */ + auto callback = [callstate](const Status &s, size_t bytes) { + callstate->set_value(std::make_tuple(s,bytes)); + }; - /* wait for async to finish */ - auto returnstate = future.get(); - stat = std::get<0>(returnstate); + PositionRead(buf, *nbyte, offset, callback); - if (!stat.ok()) { - return stat; - } + /* wait for async to finish */ + auto returnstate = future.get(); + auto stat = std::get<0>(returnstate); - size_t bytesRead = std::get<1>(returnstate); - *nbyte = *nbyte - bytesRead; - totalBytesRead += bytesRead; - offset += bytesRead; + if (!stat.ok()) { + return stat; } - /* Update the bytes read for return */ - *nbyte = totalBytesRead; + + *nbyte = std::get<1>(returnstate); return stat; } @@ -118,8 +110,8 @@ Status FileHandleImpl::Read(void *buf, size_t *nbyte) { if(!stat.ok()) { return stat; } - offset_ += *nbyte; + offset_ += *nbyte; return Status::OK(); }