diff options
Diffstat (limited to 'netfs/fuse/fuseFiles.cpp')
-rw-r--r-- | netfs/fuse/fuseFiles.cpp | 62 |
1 files changed, 47 insertions, 15 deletions
diff --git a/netfs/fuse/fuseFiles.cpp b/netfs/fuse/fuseFiles.cpp index a44f56e..9baf51f 100644 --- a/netfs/fuse/fuseFiles.cpp +++ b/netfs/fuse/fuseFiles.cpp @@ -184,24 +184,56 @@ namespace NetFS { auto remote = of->remote; auto bytes = reinterpret_cast<const ::Ice::Byte *>(buf); if (fcr->Async) { - waitOnWriteRangeAndThen<void>(s, o, of, [o, s, bytes, &of, remote](const auto & key) { - auto p = std::make_shared<OpenFile::WriteState>(); - of->bg.insert({key, p}); - remote->writeAsync( - o, safe {s}, std::make_pair(bytes, bytes + s), - [p, of, key]() { - p->promise.set_value(); - ScopeLock(of->mutex) { - of->bg.erase(key); - } - }, - [p, of](auto e) { - p->promise.set_exception(e); + auto sendSome = [&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>(); + of->bg.insert({key, p}); + remote->writeAsync( + o, blockSize, std::make_pair(bytes, bytes + blockSize), + [p, of, key]() { + p->promise.set_value(); + ScopeLock(of->mutex) { + of->bg.erase(key); + } + }, + [p, of](auto e) { + p->promise.set_exception(e); + }); }); - }); + bytes += blockSize; + o += blockSize; + }; + auto bs = of->blockSizes(s); + if (bs.size1) { + sendSome(bs.size1); + } + while (bs.N--) { + sendSome(bs.sizeN); + } } else { - remote->write(o, safe {s}, std::make_pair(bytes, bytes + s)); + 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)); + } } return safe {s}; } |