diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-05-07 13:28:52 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-05-07 13:28:52 +0100 |
commit | 15f6957e389bb72ad9543ab8ef4df0a211d35542 (patch) | |
tree | e9b3c04319a831109fbf2eaef002be6d340c3023 | |
parent | Add missing type suffixes (diff) | |
download | netfs-15f6957e389bb72ad9543ab8ef4df0a211d35542.tar.bz2 netfs-15f6957e389bb72ad9543ab8ef4df0a211d35542.tar.xz netfs-15f6957e389bb72ad9543ab8ef4df0a211d35542.zip |
Simplify blockSize iteration
-rw-r--r-- | netfs/fuse/fuseFiles.cpp | 56 |
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}; } |