diff --git a/src/lib/nfs/Connection.cxx b/src/lib/nfs/Connection.cxx index 6a58c865a..ca7ff5470 100644 --- a/src/lib/nfs/Connection.cxx +++ b/src/lib/nfs/Connection.cxx @@ -196,7 +196,7 @@ NfsConnection::AddLease(NfsLease &lease) new_leases.push_back(&lease); - DeferredMonitor::Schedule(); + defer_new_lease.Schedule(); } void @@ -363,9 +363,9 @@ NfsConnection::DestroyContext() mount_timeout_event.Cancel(); } - /* cancel pending DeferredMonitor that was scheduled to notify + /* cancel pending DeferEvent that was scheduled to notify new leases */ - DeferredMonitor::Cancel(); + defer_new_lease.Cancel(); if (SocketMonitor::IsDefined()) SocketMonitor::Steal(); @@ -631,7 +631,7 @@ NfsConnection::OnMountTimeout() } void -NfsConnection::RunDeferred() +NfsConnection::RunDeferred() noexcept { assert(GetEventLoop().IsInside()); diff --git a/src/lib/nfs/Connection.hxx b/src/lib/nfs/Connection.hxx index 2e70cbfc5..5a9864564 100644 --- a/src/lib/nfs/Connection.hxx +++ b/src/lib/nfs/Connection.hxx @@ -23,7 +23,7 @@ #include "Cancellable.hxx" #include "event/SocketMonitor.hxx" #include "event/TimerEvent.hxx" -#include "event/DeferredMonitor.hxx" +#include "event/DeferEvent.hxx" #include #include @@ -39,7 +39,7 @@ class NfsLease; /** * An asynchronous connection to a NFS server. */ -class NfsConnection : SocketMonitor, DeferredMonitor { +class NfsConnection : SocketMonitor { class CancellableCallback : public CancellablePointer { NfsConnection &connection; @@ -91,6 +91,7 @@ class NfsConnection : SocketMonitor, DeferredMonitor { void Callback(int err, void *data); }; + DeferEvent defer_new_lease; TimerEvent mount_timeout_event; std::string server, export_name; @@ -139,7 +140,7 @@ public: NfsConnection(EventLoop &_loop, const char *_server, const char *_export_name) noexcept :SocketMonitor(_loop), - DeferredMonitor(_loop), + defer_new_lease(_loop, BIND_THIS_METHOD(RunDeferred)), mount_timeout_event(_loop, BIND_THIS_METHOD(OnMountTimeout)), server(_server), export_name(_export_name), context(nullptr) {} @@ -235,8 +236,8 @@ private: /* callback for #mount_timeout_event */ void OnMountTimeout(); - /* virtual methods from DeferredMonitor */ - virtual void RunDeferred() override; + /* DeferEvent callback */ + void RunDeferred() noexcept; }; #endif diff --git a/src/lib/nfs/FileReader.cxx b/src/lib/nfs/FileReader.cxx index 5a4aa3b91..39fc77e58 100644 --- a/src/lib/nfs/FileReader.cxx +++ b/src/lib/nfs/FileReader.cxx @@ -33,7 +33,7 @@ #include NfsFileReader::NfsFileReader() - :DeferredMonitor(nfs_get_event_loop()) + :defer_open(nfs_get_event_loop(), BIND_THIS_METHOD(OnDeferredOpen)) { } @@ -50,7 +50,7 @@ NfsFileReader::Close() if (state == State::DEFER) { state = State::INITIAL; - DeferredMonitor::Cancel(); + defer_open.Cancel(); return; } @@ -122,7 +122,7 @@ NfsFileReader::Open(const char *uri) } state = State::DEFER; - DeferredMonitor::Schedule(); + defer_open.Schedule(); } void @@ -272,7 +272,7 @@ NfsFileReader::OnNfsError(std::exception_ptr &&e) } void -NfsFileReader::RunDeferred() +NfsFileReader::OnDeferredOpen() noexcept { assert(state == State::DEFER); diff --git a/src/lib/nfs/FileReader.hxx b/src/lib/nfs/FileReader.hxx index a7c50b506..d3546e9f9 100644 --- a/src/lib/nfs/FileReader.hxx +++ b/src/lib/nfs/FileReader.hxx @@ -23,7 +23,7 @@ #include "check.h" #include "Lease.hxx" #include "Callback.hxx" -#include "event/DeferredMonitor.hxx" +#include "event/DeferEvent.hxx" #include "Compiler.h" #include @@ -43,7 +43,7 @@ class NfsConnection; * To get started, derive your class from it and implement the pure * virtual methods, construct an instance, and call Open(). */ -class NfsFileReader : NfsLease, NfsCallback, DeferredMonitor { +class NfsFileReader : NfsLease, NfsCallback { enum class State { INITIAL, DEFER, @@ -63,11 +63,15 @@ class NfsFileReader : NfsLease, NfsCallback, DeferredMonitor { nfsfh *fh; + DeferEvent defer_open; + public: NfsFileReader(); ~NfsFileReader(); - using DeferredMonitor::GetEventLoop; + EventLoop &GetEventLoop() noexcept { + return defer_open.GetEventLoop(); + } void Close(); void DeferClose(); @@ -146,8 +150,8 @@ private: void OnNfsCallback(unsigned status, void *data) final; void OnNfsError(std::exception_ptr &&e) final; - /* virtual methods from DeferredMonitor */ - void RunDeferred() final; + /* DeferEvent callback */ + void OnDeferredOpen() noexcept; }; #endif diff --git a/src/storage/plugins/NfsStorage.cxx b/src/storage/plugins/NfsStorage.cxx index eec8c7682..4ccd9934b 100644 --- a/src/storage/plugins/NfsStorage.cxx +++ b/src/storage/plugins/NfsStorage.cxx @@ -33,7 +33,7 @@ #include "thread/Cond.hxx" #include "event/Loop.hxx" #include "event/Call.hxx" -#include "event/DeferredMonitor.hxx" +#include "event/DeferEvent.hxx" #include "event/TimerEvent.hxx" #include "util/StringCompare.hxx" @@ -49,7 +49,7 @@ extern "C" { #include class NfsStorage final - : public Storage, NfsLease, DeferredMonitor { + : public Storage, NfsLease { enum class State { INITIAL, CONNECTING, READY, DELAY, @@ -61,6 +61,7 @@ class NfsStorage final NfsConnection *connection; + DeferEvent defer_connect; TimerEvent reconnect_timer; Mutex mutex; @@ -71,10 +72,10 @@ class NfsStorage final public: NfsStorage(EventLoop &_loop, const char *_base, std::string &&_server, std::string &&_export_name) - :DeferredMonitor(_loop), - base(_base), + :base(_base), server(std::move(_server)), export_name(std::move(_export_name)), + defer_connect(_loop, BIND_THIS_METHOD(OnDeferredConnect)), reconnect_timer(_loop, BIND_THIS_METHOD(OnReconnectTimer)) { nfs_init(_loop); } @@ -114,8 +115,8 @@ public: reconnect_timer.Schedule(std::chrono::seconds(5)); } - /* virtual methods from DeferredMonitor */ - void RunDeferred() final { + /* DeferEvent callback */ + void OnDeferredConnect() noexcept { if (state == State::INITIAL) Connect(); } @@ -129,7 +130,7 @@ public: private: EventLoop &GetEventLoop() { - return DeferredMonitor::GetEventLoop(); + return defer_connect.GetEventLoop(); } void SetState(State _state) { @@ -173,7 +174,7 @@ private: case State::INITIAL: /* schedule connect */ mutex.unlock(); - DeferredMonitor::Schedule(); + defer_connect.Schedule(); mutex.lock(); if (state == State::INITIAL) cond.wait(mutex); @@ -195,7 +196,7 @@ private: switch (state) { case State::INITIAL: - DeferredMonitor::Cancel(); + defer_connect.Cancel(); break; case State::CONNECTING: