@@ -236,7 +236,7 @@ impl PipeConnection {
236
236
let res = unsafe { GetOverlappedResult ( self . named_pipe , ol. as_mut_ptr ( ) , & mut bytes_transfered, WAIT_FOR_EVENT ) } ;
237
237
match res {
238
238
0 => {
239
- return Err ( Error :: Windows ( io:: Error :: last_os_error ( ) . raw_os_error ( ) . unwrap ( ) ) )
239
+ return Err ( handle_windows_error ( io:: Error :: last_os_error ( ) ) )
240
240
}
241
241
_ => {
242
242
return Ok ( bytes_transfered as usize )
@@ -267,7 +267,7 @@ impl PipeConnection {
267
267
let res = unsafe { GetOverlappedResult ( self . named_pipe , ol. as_mut_ptr ( ) , & mut bytes_transfered, WAIT_FOR_EVENT ) } ;
268
268
match res {
269
269
0 => {
270
- return Err ( Error :: Windows ( io:: Error :: last_os_error ( ) . raw_os_error ( ) . unwrap ( ) ) )
270
+ return Err ( handle_windows_error ( io:: Error :: last_os_error ( ) ) )
271
271
}
272
272
_ => {
273
273
return Ok ( bytes_transfered as usize )
@@ -289,7 +289,7 @@ impl PipeConnection {
289
289
pub fn shutdown ( & self ) -> Result < ( ) > {
290
290
let result = unsafe { DisconnectNamedPipe ( self . named_pipe ) } ;
291
291
match result {
292
- 0 => Err ( Error :: Windows ( io:: Error :: last_os_error ( ) . raw_os_error ( ) . unwrap ( ) ) ) ,
292
+ 0 => Err ( handle_windows_error ( io:: Error :: last_os_error ( ) ) ) ,
293
293
_ => Ok ( ( ) ) ,
294
294
}
295
295
}
@@ -302,23 +302,23 @@ pub struct ClientConnection {
302
302
fn close_handle ( handle : isize ) -> Result < ( ) > {
303
303
let result = unsafe { CloseHandle ( handle) } ;
304
304
match result {
305
- 0 => Err ( Error :: Windows ( io:: Error :: last_os_error ( ) . raw_os_error ( ) . unwrap ( ) ) ) ,
305
+ 0 => Err ( handle_windows_error ( io:: Error :: last_os_error ( ) ) ) ,
306
306
_ => Ok ( ( ) ) ,
307
307
}
308
308
}
309
309
310
310
fn create_event ( ) -> Result < isize > {
311
311
let result = unsafe { CreateEventW ( std:: ptr:: null_mut ( ) , 0 , 1 , std:: ptr:: null_mut ( ) ) } ;
312
312
match result {
313
- 0 => Err ( Error :: Windows ( io:: Error :: last_os_error ( ) . raw_os_error ( ) . unwrap ( ) ) ) ,
313
+ 0 => Err ( handle_windows_error ( io:: Error :: last_os_error ( ) ) ) ,
314
314
_ => Ok ( result) ,
315
315
}
316
316
}
317
317
318
318
fn set_event ( event : isize ) -> Result < ( ) > {
319
319
let result = unsafe { SetEvent ( event) } ;
320
320
match result {
321
- 0 => Err ( Error :: Windows ( io:: Error :: last_os_error ( ) . raw_os_error ( ) . unwrap ( ) ) ) ,
321
+ 0 => Err ( handle_windows_error ( io:: Error :: last_os_error ( ) ) ) ,
322
322
_ => Ok ( ( ) ) ,
323
323
}
324
324
}
@@ -349,7 +349,7 @@ impl ClientConnection {
349
349
return PipeConnection :: new ( file. into_raw_handle ( ) as isize )
350
350
}
351
351
Err ( e) => {
352
- return Err ( Error :: Windows ( e . raw_os_error ( ) . unwrap ( ) ) )
352
+ return Err ( handle_windows_error ( e ) )
353
353
}
354
354
}
355
355
}
@@ -365,6 +365,14 @@ impl ClientConnection {
365
365
}
366
366
}
367
367
368
+ fn handle_windows_error ( e : io:: Error ) -> Error {
369
+ if let Some ( raw_os_err) = e. raw_os_error ( ) {
370
+ Error :: Windows ( raw_os_err)
371
+ } else {
372
+ Error :: Others ( e. to_string ( ) )
373
+ }
374
+ }
375
+
368
376
#[ cfg( test) ]
369
377
mod test {
370
378
use super :: * ;
0 commit comments