lib/nfs/Connection: migrate from TimeoutMonitor to TimerEvent

This commit is contained in:
Max Kellermann 2017-08-29 16:36:16 +02:00
parent c24b8460e0
commit 91d4b5cfed
2 changed files with 14 additions and 11 deletions

View File

@ -359,8 +359,8 @@ NfsConnection::DestroyContext()
#endif
if (!mount_finished) {
assert(TimeoutMonitor::IsActive());
TimeoutMonitor::Cancel();
assert(mount_timeout_event.IsActive());
mount_timeout_event.Cancel();
}
/* cancel pending DeferredMonitor that was scheduled to notify
@ -525,8 +525,8 @@ NfsConnection::MountCallback(int status, gcc_unused nfs_context *nfs,
mount_finished = true;
assert(TimeoutMonitor::IsActive() || in_destroy);
TimeoutMonitor::Cancel();
assert(mount_timeout_event.IsActive() || in_destroy);
mount_timeout_event.Cancel();
if (status < 0) {
auto e = FormatRuntimeError("nfs_mount_async() failed: %s",
@ -558,7 +558,7 @@ NfsConnection::MountInternal()
postponed_mount_error = std::exception_ptr();
mount_finished = false;
TimeoutMonitor::Schedule(NFS_MOUNT_TIMEOUT);
mount_timeout_event.Schedule(NFS_MOUNT_TIMEOUT);
#ifndef NDEBUG
in_service = false;
@ -619,7 +619,7 @@ NfsConnection::BroadcastError(std::exception_ptr &&e)
}
void
NfsConnection::OnTimeout()
NfsConnection::OnMountTimeout()
{
assert(GetEventLoop().IsInside());
assert(!mount_finished);

View File

@ -22,7 +22,7 @@
#include "Cancellable.hxx"
#include "event/SocketMonitor.hxx"
#include "event/TimeoutMonitor.hxx"
#include "event/TimerEvent.hxx"
#include "event/DeferredMonitor.hxx"
#include <string>
@ -39,7 +39,7 @@ class NfsLease;
/**
* An asynchronous connection to a NFS server.
*/
class NfsConnection : SocketMonitor, TimeoutMonitor, DeferredMonitor {
class NfsConnection : SocketMonitor, DeferredMonitor {
class CancellableCallback : public CancellablePointer<NfsCallback> {
NfsConnection &connection;
@ -91,6 +91,8 @@ class NfsConnection : SocketMonitor, TimeoutMonitor, DeferredMonitor {
void Callback(int err, void *data);
};
TimerEvent mount_timeout_event;
std::string server, export_name;
nfs_context *context;
@ -136,8 +138,9 @@ public:
gcc_nonnull_all
NfsConnection(EventLoop &_loop,
const char *_server, const char *_export_name) noexcept
:SocketMonitor(_loop), TimeoutMonitor(_loop),
:SocketMonitor(_loop),
DeferredMonitor(_loop),
mount_timeout_event(_loop, BIND_THIS_METHOD(OnMountTimeout)),
server(_server), export_name(_export_name),
context(nullptr) {}
@ -229,8 +232,8 @@ private:
/* virtual methods from SocketMonitor */
virtual bool OnSocketReady(unsigned flags) override;
/* virtual methods from TimeoutMonitor */
void OnTimeout() final;
/* callback for #mount_timeout_event */
void OnMountTimeout();
/* virtual methods from DeferredMonitor */
virtual void RunDeferred() override;