summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--netfs/fuse/fuseFiles.cpp56
1 files changed, 26 insertions, 30 deletions
diff --git a/netfs/fuse/fuseFiles.cpp b/netfs/fuse/fuseFiles.cpp
index 9baf51f..c1709cd 100644
--- a/netfs/fuse/fuseFiles.cpp
+++ b/netfs/fuse/fuseFiles.cpp
@@ -151,6 +151,18 @@ namespace NetFS {
}
}
+ template<typename CB>
+ void
+ blockSizeIterate(FuseApp::OpenFile::BlockSizes bs, CB && cb)
+ {
+ if (bs.size1) {
+ cb(bs.size1);
+ }
+ while (bs.N--) {
+ cb(bs.sizeN);
+ }
+ }
+
int
FuseApp::read(const char *, char * buf, size_t s, off_t o, struct fuse_file_info * fi)
{
@@ -184,7 +196,7 @@ namespace NetFS {
auto remote = of->remote;
auto bytes = reinterpret_cast<const ::Ice::Byte *>(buf);
if (fcr->Async) {
- auto sendSome = [&bytes, &o, &remote, &of](safe<size_t> blockSize) {
+ blockSizeIterate(of->blockSizes(s), [&bytes, &o, &remote, &of](safe<size_t> blockSize) {
waitOnWriteRangeAndThen<void>(
blockSize, o, of, [o, blockSize, bytes, &of, remote](const auto & key) {
auto p = std::make_shared<OpenFile::WriteState>();
@@ -203,37 +215,21 @@ namespace NetFS {
});
bytes += blockSize;
o += blockSize;
- };
- auto bs = of->blockSizes(s);
- if (bs.size1) {
- sendSome(bs.size1);
- }
- while (bs.N--) {
- sendSome(bs.sizeN);
- }
+ });
+ }
+ else if (of->bodyMaxSize < s) {
+ std::vector<std::future<void>> ops;
+ blockSizeIterate(of->blockSizes(s), [&ops, &bytes, &o, &remote](safe<size_t> blockSize) {
+ ops.emplace_back(remote->writeAsync(o, blockSize, std::make_pair(bytes, bytes + blockSize)));
+ bytes += blockSize;
+ o += blockSize;
+ });
+ std::for_each(ops.begin(), ops.end(), [](auto && op) {
+ op.get();
+ });
}
else {
- if (of->bodyMaxSize < s) {
- std::vector<std::future<void>> ops;
- auto sendSome = [&ops, &bytes, &o, &remote](safe<size_t> blockSize) {
- ops.emplace_back(remote->writeAsync(o, blockSize, std::make_pair(bytes, bytes + blockSize)));
- bytes += blockSize;
- o += blockSize;
- };
- auto bs = of->blockSizes(s);
- if (bs.size1) {
- sendSome(bs.size1);
- }
- while (bs.N--) {
- sendSome(bs.sizeN);
- }
- std::for_each(ops.begin(), ops.end(), [](auto && op) {
- op.get();
- });
- }
- else {
- remote->write(o, safe {s}, std::make_pair(bytes, bytes + s));
- }
+ remote->write(o, safe {s}, std::make_pair(bytes, bytes + s));
}
return safe {s};
}