Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F73662
leash.rs
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
leash.rs
View Options
use
std
::
sync
::
Arc
;
use
tokio
::
sync
::
Mutex
;
use
crate
::
{
Error
,
Result
};
pub
struct
NetworkLeash
{
lock
:
Arc
<
Mutex
<
()
>>
}
impl
NetworkLeash
{
pub
fn
new
()
->
Self
{
tracing
::
trace
!
(
"Creating new NetworkLeash"
);
Self
{
lock
:
Arc
::
new
(
Mutex
::
new
(())),
}
}
pub
async
fn
with_interface
<
F
,
R
>
(
&
self
,
name
:
&
str
,
operation
:
F
)
->
Result
<
R
>
where
F
:
FnOnce
(
&
mut
ifconfig
::
Iface
)
->
Result
<
R
>
+
Send
+
'
static
,
R
:
Send
+
'
static
,
{
let
_guard
=
self
.
lock
.
lock
().
await
;
let
name
=
name
.
to_string
();
tokio
::
task
::
spawn_blocking
(
move
||
{
let
mut
iface
=
ifconfig
::
Iface
::
new
(
&
name
)
?
;
operation
(
&
mut
iface
)
}).
await
?
}
pub
async
fn
gated
<
F
,
R
>
(
&
self
,
operation
:
F
)
->
Result
<
R
>
where
F
:
FnOnce
()
->
Result
<
R
>
+
Send
+
'
static
,
R
:
Send
+
'
static
,
{
let
_guard
=
self
.
lock
.
lock
().
await
;
tokio
::
task
::
spawn_blocking
(
move
||
{
operation
()
}).
await
?
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Jun 8, 8:26 AM (18 h, 56 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
47582
Default Alt Text
leash.rs (1 KB)
Attached To
rCOLLAR collar
Event Timeline
Log In to Comment