@@ -213,7 +213,7 @@ impl PipeConnection {
213
213
let res = unsafe { GetOverlappedResult ( self . named_pipe , ol. as_mut_ptr ( ) , & mut bytes_transfered, WAIT_FOR_EVENT ) } ;
214
214
match res {
215
215
0 => {
216
- return Err ( Error :: Windows ( io:: Error :: last_os_error ( ) . raw_os_error ( ) . unwrap ( ) ) )
216
+ return Err ( handle_windows_error ( io:: Error :: last_os_error ( ) ) )
217
217
}
218
218
_ => {
219
219
return Ok ( bytes_transfered as usize )
@@ -244,7 +244,7 @@ impl PipeConnection {
244
244
let res = unsafe { GetOverlappedResult ( self . named_pipe , ol. as_mut_ptr ( ) , & mut bytes_transfered, WAIT_FOR_EVENT ) } ;
245
245
match res {
246
246
0 => {
247
- return Err ( Error :: Windows ( io:: Error :: last_os_error ( ) . raw_os_error ( ) . unwrap ( ) ) )
247
+ return Err ( handle_windows_error ( io:: Error :: last_os_error ( ) ) )
248
248
}
249
249
_ => {
250
250
return Ok ( bytes_transfered as usize )
@@ -266,7 +266,7 @@ impl PipeConnection {
266
266
pub fn shutdown ( & self ) -> Result < ( ) > {
267
267
let result = unsafe { DisconnectNamedPipe ( self . named_pipe ) } ;
268
268
match result {
269
- 0 => Err ( Error :: Windows ( io:: Error :: last_os_error ( ) . raw_os_error ( ) . unwrap ( ) ) ) ,
269
+ 0 => Err ( handle_windows_error ( io:: Error :: last_os_error ( ) ) ) ,
270
270
_ => Ok ( ( ) ) ,
271
271
}
272
272
}
@@ -279,23 +279,23 @@ pub struct ClientConnection {
279
279
fn close_handle ( handle : isize ) -> Result < ( ) > {
280
280
let result = unsafe { CloseHandle ( handle) } ;
281
281
match result {
282
- 0 => Err ( Error :: Windows ( io:: Error :: last_os_error ( ) . raw_os_error ( ) . unwrap ( ) ) ) ,
282
+ 0 => Err ( handle_windows_error ( io:: Error :: last_os_error ( ) ) ) ,
283
283
_ => Ok ( ( ) ) ,
284
284
}
285
285
}
286
286
287
287
fn create_event ( ) -> Result < isize > {
288
288
let result = unsafe { CreateEventW ( std:: ptr:: null_mut ( ) , 0 , 1 , std:: ptr:: null_mut ( ) ) } ;
289
289
match result {
290
- 0 => Err ( Error :: Windows ( io:: Error :: last_os_error ( ) . raw_os_error ( ) . unwrap ( ) ) ) ,
290
+ 0 => Err ( handle_windows_error ( io:: Error :: last_os_error ( ) ) ) ,
291
291
_ => Ok ( result) ,
292
292
}
293
293
}
294
294
295
295
fn set_event ( event : isize ) -> Result < ( ) > {
296
296
let result = unsafe { SetEvent ( event) } ;
297
297
match result {
298
- 0 => Err ( Error :: Windows ( io:: Error :: last_os_error ( ) . raw_os_error ( ) . unwrap ( ) ) ) ,
298
+ 0 => Err ( handle_windows_error ( io:: Error :: last_os_error ( ) ) ) ,
299
299
_ => Ok ( ( ) ) ,
300
300
}
301
301
}
@@ -326,7 +326,7 @@ impl ClientConnection {
326
326
return PipeConnection :: new ( file. into_raw_handle ( ) as isize )
327
327
}
328
328
Err ( e) => {
329
- return Err ( Error :: Windows ( e . raw_os_error ( ) . unwrap ( ) ) )
329
+ return Err ( handle_windows_error ( e ) )
330
330
}
331
331
}
332
332
}
@@ -342,6 +342,14 @@ impl ClientConnection {
342
342
}
343
343
}
344
344
345
+ fn handle_windows_error ( e : io:: Error ) -> Error {
346
+ if let Some ( raw_os_err) = e. raw_os_error ( ) {
347
+ Error :: Windows ( raw_os_err)
348
+ } else {
349
+ Error :: Others ( e. to_string ( ) )
350
+ }
351
+ }
352
+
345
353
#[ cfg( test) ]
346
354
mod test {
347
355
use super :: * ;
0 commit comments