storage/nfs: migrate from TimeoutMonitor to TimerEvent
This commit is contained in:
parent
7ae57a3531
commit
2e471daef1
|
@ -34,7 +34,7 @@
|
||||||
#include "event/Loop.hxx"
|
#include "event/Loop.hxx"
|
||||||
#include "event/Call.hxx"
|
#include "event/Call.hxx"
|
||||||
#include "event/DeferredMonitor.hxx"
|
#include "event/DeferredMonitor.hxx"
|
||||||
#include "event/TimeoutMonitor.hxx"
|
#include "event/TimerEvent.hxx"
|
||||||
#include "util/StringCompare.hxx"
|
#include "util/StringCompare.hxx"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -49,7 +49,7 @@ extern "C" {
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
class NfsStorage final
|
class NfsStorage final
|
||||||
: public Storage, NfsLease, DeferredMonitor, TimeoutMonitor {
|
: public Storage, NfsLease, DeferredMonitor {
|
||||||
|
|
||||||
enum class State {
|
enum class State {
|
||||||
INITIAL, CONNECTING, READY, DELAY,
|
INITIAL, CONNECTING, READY, DELAY,
|
||||||
|
@ -61,6 +61,8 @@ class NfsStorage final
|
||||||
|
|
||||||
NfsConnection *connection;
|
NfsConnection *connection;
|
||||||
|
|
||||||
|
TimerEvent reconnect_timer;
|
||||||
|
|
||||||
Mutex mutex;
|
Mutex mutex;
|
||||||
Cond cond;
|
Cond cond;
|
||||||
State state;
|
State state;
|
||||||
|
@ -69,10 +71,11 @@ 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), TimeoutMonitor(_loop),
|
: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)),
|
||||||
|
reconnect_timer(_loop, BIND_THIS_METHOD(OnReconnectTimer)),
|
||||||
state(State::INITIAL) {
|
state(State::INITIAL) {
|
||||||
nfs_init(_loop);
|
nfs_init(_loop);
|
||||||
}
|
}
|
||||||
|
@ -102,14 +105,14 @@ public:
|
||||||
assert(state == State::CONNECTING);
|
assert(state == State::CONNECTING);
|
||||||
|
|
||||||
SetState(State::DELAY, std::move(e));
|
SetState(State::DELAY, std::move(e));
|
||||||
TimeoutMonitor::Schedule(std::chrono::minutes(1));
|
reconnect_timer.Schedule(std::chrono::minutes(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnNfsConnectionDisconnected(std::exception_ptr e) final {
|
void OnNfsConnectionDisconnected(std::exception_ptr e) final {
|
||||||
assert(state == State::READY);
|
assert(state == State::READY);
|
||||||
|
|
||||||
SetState(State::DELAY, std::move(e));
|
SetState(State::DELAY, std::move(e));
|
||||||
TimeoutMonitor::Schedule(std::chrono::seconds(5));
|
reconnect_timer.Schedule(std::chrono::seconds(5));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* virtual methods from DeferredMonitor */
|
/* virtual methods from DeferredMonitor */
|
||||||
|
@ -118,8 +121,8 @@ public:
|
||||||
Connect();
|
Connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* virtual methods from TimeoutMonitor */
|
/* callback for #reconnect_timer */
|
||||||
void OnTimeout() final {
|
void OnReconnectTimer() {
|
||||||
assert(state == State::DELAY);
|
assert(state == State::DELAY);
|
||||||
|
|
||||||
Connect();
|
Connect();
|
||||||
|
@ -203,7 +206,7 @@ private:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case State::DELAY:
|
case State::DELAY:
|
||||||
TimeoutMonitor::Cancel();
|
reconnect_timer.Cancel();
|
||||||
SetState(State::INITIAL);
|
SetState(State::INITIAL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue