aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-12-14 21:16:34 +0100
committerMax Kellermann <max@duempel.org>2014-12-15 00:45:13 +0100
commita48704925d6c3e5c01057192403e55f3663b315c (patch)
tree551f94bfa11da645dc01e61bd38d746383436b87
parent68d1abdb851a839fefc55b00eb49eb22a399595b (diff)
downloadmpd-a48704925d6c3e5c01057192403e55f3663b315c.tar.gz
mpd-a48704925d6c3e5c01057192403e55f3663b315c.tar.xz
mpd-a48704925d6c3e5c01057192403e55f3663b315c.zip
storage/nfs: add timeout
Diffstat (limited to '')
-rw-r--r--NEWS2
-rw-r--r--src/lib/nfs/Blocking.cxx7
-rw-r--r--src/lib/nfs/Blocking.hxx9
3 files changed, 15 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index c84f4b891..34ab55db9 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,8 @@ ver 0.19.7 (not yet released)
- nfs: fix memory leak on connection failure
- nfs: fix reconnect after mount failure
- nfs: implement mount timeout (60 seconds)
+* storage
+ - nfs: implement I/O timeout (60 seconds)
* playlist
- don't skip non-existent songs in "listplaylist"
* fix memory allocator bug on Windows
diff --git a/src/lib/nfs/Blocking.cxx b/src/lib/nfs/Blocking.cxx
index 5f769c408..58eaf6af2 100644
--- a/src/lib/nfs/Blocking.cxx
+++ b/src/lib/nfs/Blocking.cxx
@@ -20,7 +20,9 @@
#include "config.h"
#include "Blocking.hxx"
#include "Connection.hxx"
+#include "Domain.hxx"
#include "event/Call.hxx"
+#include "util/Error.hxx"
bool
BlockingNfsOperation::Run(Error &_error)
@@ -31,7 +33,10 @@ BlockingNfsOperation::Run(Error &_error)
[this](){ connection.AddLease(*this); });
/* wait for completion */
- LockWaitFinished();
+ if (!LockWaitFinished()) {
+ _error.Set(nfs_domain, 0, "Timeout");
+ return false;
+ }
/* check for error */
if (error.IsDefined()) {
diff --git a/src/lib/nfs/Blocking.hxx b/src/lib/nfs/Blocking.hxx
index f8354822d..eb16dfb8c 100644
--- a/src/lib/nfs/Blocking.hxx
+++ b/src/lib/nfs/Blocking.hxx
@@ -35,6 +35,8 @@ class NfsConnection;
* thread, and method Run() waits for completion.
*/
class BlockingNfsOperation : protected NfsCallback, NfsLease {
+ static constexpr unsigned timeout_ms = 60000;
+
Mutex mutex;
Cond cond;
@@ -52,10 +54,13 @@ public:
bool Run(Error &error);
private:
- void LockWaitFinished() {
+ bool LockWaitFinished() {
const ScopeLock protect(mutex);
while (!finished)
- cond.wait(mutex);
+ if (!cond.timed_wait(mutex, timeout_ms))
+ return false;
+
+ return true;
}
/**