15
15
*/
16
16
17
17
use crate :: error:: Result ;
18
+ use crate :: error:: Error ;
18
19
19
20
use mio:: windows:: NamedPipe ;
20
21
@@ -29,7 +30,7 @@ use std::sync::{Arc, Mutex};
29
30
use std:: { io} ;
30
31
31
32
32
- use windows_sys:: Win32 :: Foundation :: { ERROR_NO_DATA , INVALID_HANDLE_VALUE , CloseHandle , GetLastError } ;
33
+ use windows_sys:: Win32 :: Foundation :: { ERROR_NO_DATA , INVALID_HANDLE_VALUE , CloseHandle } ;
33
34
use windows_sys:: Win32 :: Storage :: FileSystem :: {
34
35
FILE_FLAG_FIRST_PIPE_INSTANCE , FILE_FLAG_OVERLAPPED , PIPE_ACCESS_DUPLEX ,
35
36
} ;
@@ -130,13 +131,13 @@ impl PipeListener {
130
131
self . first_instance . swap ( false , Ordering :: SeqCst ) ;
131
132
}
132
133
133
- let h = match unsafe { CreateNamedPipeW ( name. as_ptr ( ) , open_mode, PIPE_TYPE_BYTE , PIPE_UNLIMITED_INSTANCES , 65536 , 65536 , 0 , std:: ptr:: null_mut ( ) ) } {
134
+ match unsafe { CreateNamedPipeW ( name. as_ptr ( ) , open_mode, PIPE_TYPE_BYTE , PIPE_UNLIMITED_INSTANCES , 65536 , 65536 , 0 , std:: ptr:: null_mut ( ) ) } {
134
135
INVALID_HANDLE_VALUE => {
135
- return Err ( io:: Error :: last_os_error ( ) ) ;
136
+ return Err ( io:: Error :: last_os_error ( ) )
136
137
}
137
138
h => {
138
139
let pipe = unsafe { NamedPipe :: from_raw_handle ( h as RawHandle ) } ;
139
- Ok ( pipe)
140
+ return Ok ( pipe)
140
141
} ,
141
142
} ;
142
143
}
@@ -152,9 +153,6 @@ pub struct PipeConnection {
152
153
poller : Mutex < Poll > ,
153
154
}
154
155
155
- unsafe impl Send for PipeConnection { }
156
- unsafe impl Sync for PipeConnection { }
157
-
158
156
impl PipeConnection {
159
157
pub ( crate ) fn new ( h : RawHandle ) -> PipeConnection {
160
158
let mut pipe = unsafe { NamedPipe :: from_raw_handle ( h as RawHandle ) } ;
@@ -219,14 +217,14 @@ impl PipeConnection {
219
217
continue ;
220
218
}
221
219
Err ( e) if e. raw_os_error ( ) == Some ( ERROR_NO_DATA as i32 ) => {
222
- return Err ( crate :: Error :: Windows ( e. raw_os_error ( ) . unwrap ( ) ) )
220
+ return Err ( Error :: Windows ( e. raw_os_error ( ) . unwrap ( ) ) )
223
221
}
224
222
Err ( e) if e. raw_os_error ( ) . is_some ( ) => {
225
- return Err ( crate :: Error :: Windows ( e. raw_os_error ( ) . unwrap ( ) ) )
223
+ return Err ( Error :: Windows ( e. raw_os_error ( ) . unwrap ( ) ) )
226
224
}
227
225
Err ( e) => {
228
226
trace ! ( "Error writing to pipe: {}" , e) ;
229
- return Err ( crate :: Error :: Others ( e. to_string ( ) ) ) ;
227
+ return Err ( Error :: Others ( e. to_string ( ) ) ) ;
230
228
}
231
229
}
232
230
}
@@ -236,15 +234,15 @@ impl PipeConnection {
236
234
let h = self . named_pipe . lock ( ) . unwrap ( ) . as_raw_handle ( ) ;
237
235
let result = unsafe { CloseHandle ( h as isize ) } ;
238
236
match result {
239
- 0 => Err ( crate :: Error :: Windows ( io:: Error :: last_os_error ( ) ) ) ,
237
+ 0 => Err ( Error :: Windows ( io:: Error :: last_os_error ( ) . raw_os_error ( ) . unwrap ( ) ) ) ,
240
238
_ => Ok ( ( ) )
241
239
}
242
240
}
243
241
244
242
pub fn shutdown ( & self ) -> Result < ( ) > {
245
243
match self . named_pipe . lock ( ) . unwrap ( ) . disconnect ( ) {
246
244
Ok ( _) => Ok ( ( ) ) ,
247
- Err ( e) => Err ( crate :: Error :: Others ( e. to_string ( ) ) )
245
+ Err ( e) => Err ( Error :: Others ( e. to_string ( ) ) )
248
246
}
249
247
}
250
248
}
0 commit comments