@@ -13,7 +13,6 @@ use libc::{
13
13
} ;
14
14
use netlink_packet_route:: route:: { RouteProtocol , RouteScope } ;
15
15
use netlink_packet_route:: rule:: RuleAction ;
16
- use parking_lot:: Mutex ;
17
16
use rtnetlink:: RuleAddRequest ;
18
17
use rtnetlink:: { new_connection, Error :: NetlinkError , Handle } ;
19
18
use std:: net:: IpAddr ;
@@ -50,7 +49,7 @@ pub struct Tun {
50
49
connection : tokio:: task:: JoinHandle < ( ) > ,
51
50
fd : AsyncFd < RawFd > ,
52
51
53
- worker : Mutex < Option < BoxFuture < ' static , Result < ( ) > > > > ,
52
+ worker : Option < BoxFuture < ' static , Result < ( ) > > > ,
54
53
}
55
54
56
55
impl fmt:: Debug for Tun {
@@ -79,15 +78,14 @@ impl Tun {
79
78
write ( self . fd . as_raw_fd ( ) , buf)
80
79
}
81
80
82
- pub fn poll_read ( & self , buf : & mut [ u8 ] , cx : & mut Context < ' _ > ) -> Poll < io:: Result < usize > > {
83
- let mut guard = self . worker . lock ( ) ;
84
- if let Some ( worker) = guard. as_mut ( ) {
81
+ pub fn poll_read ( & mut self , buf : & mut [ u8 ] , cx : & mut Context < ' _ > ) -> Poll < io:: Result < usize > > {
82
+ if let Some ( worker) = self . worker . as_mut ( ) {
85
83
match worker. poll_unpin ( cx) {
86
84
Poll :: Ready ( Ok ( ( ) ) ) => {
87
- * guard = None ;
85
+ self . worker = None ;
88
86
}
89
87
Poll :: Ready ( Err ( e) ) => {
90
- * guard = None ;
88
+ self . worker = None ;
91
89
return Poll :: Ready ( Err ( io:: Error :: new ( io:: ErrorKind :: Other , e) ) ) ;
92
90
}
93
91
Poll :: Pending => return Poll :: Pending ,
@@ -135,13 +133,13 @@ impl Tun {
135
133
handle : handle. clone ( ) ,
136
134
connection : join_handle,
137
135
fd : AsyncFd :: new ( fd) ?,
138
- worker : Mutex :: new ( Some (
136
+ worker : Some (
139
137
set_iface_config ( config. clone ( ) , dns_config, handle, dns_control_method) . boxed ( ) ,
140
- ) ) ,
138
+ ) ,
141
139
} )
142
140
}
143
141
144
- pub fn add_route ( & self , route : IpNetwork , _: & impl Callbacks ) -> Result < Option < Self > > {
142
+ pub fn add_route ( & mut self , route : IpNetwork , _: & impl Callbacks ) -> Result < Option < Self > > {
145
143
let handle = self . handle . clone ( ) ;
146
144
147
145
let add_route_worker = async move {
@@ -190,11 +188,10 @@ impl Tun {
190
188
}
191
189
} ;
192
190
193
- let mut guard = self . worker . lock ( ) ;
194
- match guard. take ( ) {
195
- None => * guard = Some ( add_route_worker. boxed ( ) ) ,
191
+ match self . worker . take ( ) {
192
+ None => self . worker = Some ( add_route_worker. boxed ( ) ) ,
196
193
Some ( current_worker) => {
197
- * guard = Some (
194
+ self . worker = Some (
198
195
async move {
199
196
current_worker. await ?;
200
197
add_route_worker. await ?;
0 commit comments