Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
1ccd2a7b
Commit
1ccd2a7b
authored
Nov 10, 2017
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib/nfs: migrate from DeferredMonitor to DeferEvent
parent
4c1d29c8
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
27 deletions
+33
-27
Connection.cxx
src/lib/nfs/Connection.cxx
+4
-4
Connection.hxx
src/lib/nfs/Connection.hxx
+6
-5
FileReader.cxx
src/lib/nfs/FileReader.cxx
+4
-4
FileReader.hxx
src/lib/nfs/FileReader.hxx
+9
-5
NfsStorage.cxx
src/storage/plugins/NfsStorage.cxx
+10
-9
No files found.
src/lib/nfs/Connection.cxx
View file @
1ccd2a7b
...
@@ -196,7 +196,7 @@ NfsConnection::AddLease(NfsLease &lease)
...
@@ -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()
...
@@ -363,9 +363,9 @@ NfsConnection::DestroyContext()
mount_timeout_event
.
Cancel
();
mount_timeout_event
.
Cancel
();
}
}
/* cancel pending Defer
redMonitor
that was scheduled to notify
/* cancel pending Defer
Event
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()
...
@@ -631,7 +631,7 @@ NfsConnection::OnMountTimeout()
}
}
void
void
NfsConnection
::
RunDeferred
()
NfsConnection
::
RunDeferred
()
noexcept
{
{
assert
(
GetEventLoop
().
IsInside
());
assert
(
GetEventLoop
().
IsInside
());
...
...
src/lib/nfs/Connection.hxx
View file @
1ccd2a7b
...
@@ -23,7 +23,7 @@
...
@@ -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/Defer
redMonitor
.hxx"
#include "event/Defer
Event
.hxx"
#include <string>
#include <string>
#include <list>
#include <list>
...
@@ -39,7 +39,7 @@ class NfsLease;
...
@@ -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 {
...
@@ -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:
...
@@ -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:
...
@@ -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
*/
v
irtual
void
RunDeferred
()
override
;
v
oid
RunDeferred
()
noexcept
;
};
};
#endif
#endif
src/lib/nfs/FileReader.cxx
View file @
1ccd2a7b
...
@@ -33,7 +33,7 @@
...
@@ -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()
...
@@ -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)
...
@@ -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)
...
@@ -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
);
...
...
src/lib/nfs/FileReader.hxx
View file @
1ccd2a7b
...
@@ -23,7 +23,7 @@
...
@@ -23,7 +23,7 @@
#include "check.h"
#include "check.h"
#include "Lease.hxx"
#include "Lease.hxx"
#include "Callback.hxx"
#include "Callback.hxx"
#include "event/Defer
redMonitor
.hxx"
#include "event/Defer
Event
.hxx"
#include "Compiler.h"
#include "Compiler.h"
#include <string>
#include <string>
...
@@ -43,7 +43,7 @@ class NfsConnection;
...
@@ -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 {
...
@@ -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:
...
@@ -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
src/storage/plugins/NfsStorage.cxx
View file @
1ccd2a7b
...
@@ -33,7 +33,7 @@
...
@@ -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/Defer
redMonitor
.hxx"
#include "event/Defer
Event
.hxx"
#include "event/TimerEvent.hxx"
#include "event/TimerEvent.hxx"
#include "util/StringCompare.hxx"
#include "util/StringCompare.hxx"
...
@@ -49,7 +49,7 @@ extern "C" {
...
@@ -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
...
@@ -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
...
@@ -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:
...
@@ -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:
...
@@ -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:
...
@@ -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:
...
@@ -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
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment