1
1
use super :: TunConfig ;
2
- use nix:: fcntl;
3
2
#[ cfg( target_os = "macos" ) ]
4
3
use std:: io;
5
4
use std:: {
6
5
net:: IpAddr ,
7
6
ops:: Deref ,
8
- os:: unix:: io:: { AsRawFd , IntoRawFd , RawFd } ,
7
+ os:: unix:: io:: { AsRawFd , RawFd } ,
9
8
} ;
10
9
use tun:: { AbstractDevice , Configuration } ;
11
10
@@ -31,10 +30,6 @@ pub enum Error {
31
30
#[ error( "Unable to open a tunnel device" ) ]
32
31
CreateDevice ( #[ source] tun:: Error ) ,
33
32
34
- /// Failed to apply async flags to tunnel device
35
- #[ error( "Failed to apply async flags to tunnel device" ) ]
36
- SetDeviceAsync ( #[ source] nix:: Error ) ,
37
-
38
33
/// Failed to enable/disable link device
39
34
#[ error( "Failed to enable/disable link device" ) ]
40
35
ToggleDevice ( #[ source] tun:: Error ) ,
@@ -107,7 +102,7 @@ impl Deref for UnixTun {
107
102
108
103
/// A tunnel device
109
104
pub struct TunnelDevice {
110
- dev : tun:: Device ,
105
+ dev : tun:: AsyncDevice ,
111
106
}
112
107
113
108
/// A tunnel device builder.
@@ -121,15 +116,7 @@ pub struct TunnelDeviceBuilder {
121
116
impl TunnelDeviceBuilder {
122
117
/// Create a [`TunnelDevice`] from this builder.
123
118
pub fn create ( self ) -> Result < TunnelDevice , Error > {
124
- fn apply_async_flags ( fd : RawFd ) -> Result < ( ) , nix:: Error > {
125
- fcntl:: fcntl ( fd, fcntl:: FcntlArg :: F_GETFL ) ?;
126
- let arg = fcntl:: FcntlArg :: F_SETFL ( fcntl:: OFlag :: O_RDWR | fcntl:: OFlag :: O_NONBLOCK ) ;
127
- fcntl:: fcntl ( fd, arg) ?;
128
- Ok ( ( ) )
129
- }
130
-
131
- let dev = tun:: create ( & self . config ) . map_err ( Error :: CreateDevice ) ?;
132
- apply_async_flags ( dev. as_raw_fd ( ) ) . map_err ( Error :: SetDeviceAsync ) ?;
119
+ let dev = tun:: create_as_async ( & self . config ) . map_err ( Error :: CreateDevice ) ?;
133
120
Ok ( TunnelDevice { dev } )
134
121
}
135
122
@@ -160,12 +147,6 @@ impl AsRawFd for TunnelDevice {
160
147
}
161
148
}
162
149
163
- impl IntoRawFd for TunnelDevice {
164
- fn into_raw_fd ( self ) -> RawFd {
165
- self . dev . into_raw_fd ( )
166
- }
167
- }
168
-
169
150
impl TunnelDevice {
170
151
#[ cfg( target_os = "linux" ) ]
171
152
fn set_ip ( & mut self , ip : IpAddr ) -> Result < ( ) , Error > {
0 commit comments