diff options
author | Max Kellermann <max@duempel.org> | 2014-10-06 09:01:46 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-10-07 06:35:46 +0200 |
commit | 61b3aaaa0791ca6ac327de6c44a107b99ce78926 (patch) | |
tree | 3caba184521562287fb655f3916d2179f7b3549d /src | |
parent | b5119d79580d923602f9b144f9b194814317e6e4 (diff) | |
download | mpd-61b3aaaa0791ca6ac327de6c44a107b99ce78926.tar.gz mpd-61b3aaaa0791ca6ac327de6c44a107b99ce78926.tar.xz mpd-61b3aaaa0791ca6ac327de6c44a107b99ce78926.zip |
lib/nfs/Connection: add method Stat(path)
Diffstat (limited to '')
-rw-r--r-- | src/lib/nfs/Connection.cxx | 30 | ||||
-rw-r--r-- | src/lib/nfs/Connection.hxx | 3 |
2 files changed, 33 insertions, 0 deletions
diff --git a/src/lib/nfs/Connection.cxx b/src/lib/nfs/Connection.cxx index e5dc87727..33e75a7c5 100644 --- a/src/lib/nfs/Connection.cxx +++ b/src/lib/nfs/Connection.cxx @@ -35,6 +35,21 @@ extern "C" { #include <poll.h> /* for POLLIN, POLLOUT */ inline bool +NfsConnection::CancellableCallback::Stat(nfs_context *ctx, + const char *path, + Error &error) +{ + int result = nfs_stat_async(ctx, path, Callback, this); + if (result < 0) { + error.Format(nfs_domain, "nfs_stat_async() failed: %s", + nfs_get_error(ctx)); + return false; + } + + return true; +} + +inline bool NfsConnection::CancellableCallback::Open(nfs_context *ctx, const char *path, int flags, Error &error) @@ -177,6 +192,21 @@ NfsConnection::RemoveLease(NfsLease &lease) } bool +NfsConnection::Stat(const char *path, NfsCallback &callback, Error &error) +{ + assert(!callbacks.Contains(callback)); + + auto &c = callbacks.Add(callback, *this, false); + if (!c.Stat(context, path, error)) { + callbacks.Remove(c); + return false; + } + + ScheduleSocket(); + return true; +} + +bool NfsConnection::Open(const char *path, int flags, NfsCallback &callback, Error &error) { diff --git a/src/lib/nfs/Connection.hxx b/src/lib/nfs/Connection.hxx index d0a8a5da2..a82921d4e 100644 --- a/src/lib/nfs/Connection.hxx +++ b/src/lib/nfs/Connection.hxx @@ -64,6 +64,8 @@ class NfsConnection : SocketMonitor, DeferredMonitor { connection(_connection), open(_open), close_fh(nullptr) {} + bool Stat(nfs_context *context, const char *path, + Error &error); bool Open(nfs_context *context, const char *path, int flags, Error &error); bool Stat(nfs_context *context, struct nfsfh *fh, @@ -155,6 +157,7 @@ public: void AddLease(NfsLease &lease); void RemoveLease(NfsLease &lease); + bool Stat(const char *path, NfsCallback &callback, Error &error); bool Open(const char *path, int flags, NfsCallback &callback, Error &error); bool Stat(struct nfsfh *fh, NfsCallback &callback, Error &error); |