diff options
Diffstat (limited to 'netfs/fuse/fuseFiles.cpp')
-rw-r--r-- | netfs/fuse/fuseFiles.cpp | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/netfs/fuse/fuseFiles.cpp b/netfs/fuse/fuseFiles.cpp index 222cab0..858a0a9 100644 --- a/netfs/fuse/fuseFiles.cpp +++ b/netfs/fuse/fuseFiles.cpp @@ -1,11 +1,17 @@ #include <string.h> #include "fuseApp.impl.h" +#include "fuseFiles.h" #include "lockHelpers.h" #include <entCache.h> #include <mutex> namespace NetFS { -FuseApp::OpenFile::OpenFile(FilePrx r, const std::string & p, int f) : +FuseApp::OpenFile::WriteState::WriteState() : + future(promise.get_future().share()) +{ +} + +FuseApp::OpenFile::OpenFile(FilePrxPtr r, const std::string & p, int f) : remote(r), path(p), flags(f) @@ -24,7 +30,7 @@ FuseApp::OpenFile::wait() const { SharedLock(_lock); for (const auto & w : bg) { - w.second->waitForCompleted(); + w.second->future.wait(); } } @@ -37,7 +43,7 @@ FuseApp::OpenFile::flush() }; while (auto w = first()) { // background operations are void, so no need to actually get the return value - w->throwLocalException(); + w->future.wait(); } } @@ -123,13 +129,13 @@ FuseApp::waitOnWriteRangeAndThen(size_t s, off_t o, const OpenFilePtr & of, cons else { // Wait for them whilst unlocked _l.release()->unlock(); - std::vector<Ice::AsyncResultPtr> overlap; + std::vector<std::shared_ptr<OpenFile::WriteState>> overlap; overlap.reserve(std::distance(R.first, R.second)); for (auto i = R.first; i != R.second; i++) { overlap.push_back(i->second); } for (const auto & r : overlap) { - r->waitForCompleted(); + r->future.wait(); } // Cause this thread to yield so the callback can acquire _lock usleep(0); @@ -163,12 +169,19 @@ FuseApp::write(const char *, const char * buf, size_t s, off_t o, struct fuse_fi auto remote = of->remote; if (fcr->Async) { waitOnWriteRangeAndThen<void>(s, o, of, [o, s, buf, &of, &remote](const auto & key){ - auto r = remote->begin_write(o, s, Buffer(buf, buf + s), [of,key](const Ice::AsyncResultPtr &) { + auto p = std::make_shared<OpenFile::WriteState>(); + remote->writeAsync(o, s, Buffer(buf, buf + s), [p,of,key]() { + p->promise.set_value(); + ScopeLock(of->_lock) { + of->bg.erase(key); + } + }, [p,of,key](auto e) { + p->promise.set_exception(e); ScopeLock(of->_lock) { of->bg.erase(key); } }); - of->bg.insert({key, r}); + of->bg.insert({key, p}); }); } else { |