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