Skip to content

Commit d5b76e3

Browse files
committed
Fix up windows files
Signed-off-by: James Sturtevant <[email protected]>
1 parent 1613bf8 commit d5b76e3

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

example/utils.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#![allow(dead_code)]
2-
use std::fs;
32
use std::io::Result;
4-
use std::path::Path;
53

64
#[cfg(unix)]
75
pub const SOCK_ADDR: &str = r"unix:///tmp/ttrpc-test";
@@ -15,15 +13,15 @@ pub fn remove_if_sock_exist(sock_addr: &str) -> Result<()> {
1513
.strip_prefix("unix://")
1614
.expect("socket address is not expected");
1715

18-
if Path::new(path).exists() {
19-
fs::remove_file(path)?;
16+
if std::path::Path::new(path).exists() {
17+
std::fs::remove_file(path)?;
2018
}
2119

2220
Ok(())
2321
}
2422

2523
#[cfg(windows)]
26-
pub fn remove_if_sock_exist(sock_addr: &str) -> Result<()> {
24+
pub fn remove_if_sock_exist(_sock_addr: &str) -> Result<()> {
2725
//todo force close file handle?
2826

2927
Ok(())

src/sync/sys/windows/net.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
use crate::error::Result;
18+
use crate::error::Error;
1819

1920
use mio::windows::NamedPipe;
2021

@@ -29,7 +30,7 @@ use std::sync::{Arc, Mutex};
2930
use std::{io};
3031

3132

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};
3334
use windows_sys::Win32::Storage::FileSystem::{
3435
FILE_FLAG_FIRST_PIPE_INSTANCE, FILE_FLAG_OVERLAPPED, PIPE_ACCESS_DUPLEX,
3536
};
@@ -130,13 +131,13 @@ impl PipeListener {
130131
self.first_instance.swap(false, Ordering::SeqCst);
131132
}
132133

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())} {
134135
INVALID_HANDLE_VALUE => {
135-
return Err(io::Error::last_os_error());
136+
return Err(io::Error::last_os_error())
136137
}
137138
h => {
138139
let pipe = unsafe { NamedPipe::from_raw_handle(h as RawHandle) };
139-
Ok(pipe)
140+
return Ok(pipe)
140141
},
141142
};
142143
}
@@ -152,9 +153,6 @@ pub struct PipeConnection {
152153
poller: Mutex<Poll>,
153154
}
154155

155-
unsafe impl Send for PipeConnection {}
156-
unsafe impl Sync for PipeConnection {}
157-
158156
impl PipeConnection {
159157
pub(crate) fn new(h: RawHandle) -> PipeConnection {
160158
let mut pipe = unsafe { NamedPipe::from_raw_handle(h as RawHandle) };
@@ -219,14 +217,14 @@ impl PipeConnection {
219217
continue;
220218
}
221219
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()))
223221
}
224222
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()))
226224
}
227225
Err(e) => {
228226
trace!("Error writing to pipe: {}", e);
229-
return Err(crate::Error::Others(e.to_string()));
227+
return Err(Error::Others(e.to_string()));
230228
}
231229
}
232230
}
@@ -236,15 +234,15 @@ impl PipeConnection {
236234
let h = self.named_pipe.lock().unwrap().as_raw_handle();
237235
let result = unsafe { CloseHandle(h as isize) };
238236
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())),
240238
_ => Ok(())
241239
}
242240
}
243241

244242
pub fn shutdown(&self) -> Result<()> {
245243
match self.named_pipe.lock().unwrap().disconnect() {
246244
Ok(_) => Ok(()),
247-
Err(e) => Err(crate::Error::Others(e.to_string()))
245+
Err(e) => Err(Error::Others(e.to_string()))
248246
}
249247
}
250248
}

0 commit comments

Comments
 (0)