You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The connect namedpipe thread would be in a suspended state when shutdown on the server is called. Setting the event to a signalled state to wake the thread up so everything can shut down properly.
Signed-off-by: James Sturtevant <[email protected]>
Copy file name to clipboardExpand all lines: src/sync/sys/windows/net.rs
+46-21Lines changed: 46 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -30,14 +30,15 @@ use windows_sys::Win32::Foundation::{ CloseHandle, ERROR_IO_PENDING, ERROR_PIPE_
30
30
use windows_sys::Win32::Storage::FileSystem::{ReadFile,WriteFile,FILE_FLAG_FIRST_PIPE_INSTANCE,FILE_FLAG_OVERLAPPED,PIPE_ACCESS_DUPLEX};
31
31
use windows_sys::Win32::System::IO::{GetOverlappedResult,OVERLAPPED};
32
32
use windows_sys::Win32::System::Pipes::{CreateNamedPipeW,ConnectNamedPipe,DisconnectNamedPipe,PIPE_WAIT,PIPE_UNLIMITED_INSTANCES,PIPE_REJECT_REMOTE_CLIENTS};
33
-
use windows_sys::Win32::System::Threading::CreateEventW;
33
+
use windows_sys::Win32::System::Threading::{CreateEventW,SetEvent};
// Create a new pipe instance for every new client
86
-
let np = self.new_instance().unwrap();
87
-
let ol = Overlapped::new();
83
+
let instance = self.new_instance()?;
84
+
let np = matchPipeConnection::new(instance){
85
+
Ok(np) => np,
86
+
Err(e) => {
87
+
returnErr(io::Error::new(
88
+
io::ErrorKind::Other,
89
+
format!("failed to create new pipe instance: {:?}", e),
90
+
));
91
+
}
92
+
};
93
+
94
+
let ol = Overlapped::new_with_event(self.connection_event);
88
95
89
96
trace!("listening for connection");
90
-
let result = unsafe{ConnectNamedPipe(np, ol.as_mut_ptr())};
97
+
let result = unsafe{ConnectNamedPipe(np.named_pipe, ol.as_mut_ptr())};
91
98
if result != 0{
92
99
returnErr(io::Error::last_os_error());
93
100
}
94
101
95
102
match io::Error::last_os_error(){
96
103
e if e.raw_os_error() == Some(ERROR_IO_PENDINGasi32) => {
97
104
letmut bytes_transfered = 0;
98
-
let res = unsafe{GetOverlappedResult(np, ol.as_mut_ptr(),&mut bytes_transfered,WAIT_FOR_EVENT)};
105
+
let res = unsafe{GetOverlappedResult(np.named_pipe, ol.as_mut_ptr(),&mut bytes_transfered,WAIT_FOR_EVENT)};
99
106
match res {
100
107
0 => {
101
108
returnErr(io::Error::last_os_error());
102
109
}
103
110
_ => {
104
-
Ok(Some(PipeConnection::new(np)))
111
+
Ok(Some(np))
105
112
}
106
113
}
107
114
}
108
115
e if e.raw_os_error() == Some(ERROR_PIPE_CONNECTEDasi32) => {
109
-
Ok(Some(PipeConnection::new(np)))
116
+
Ok(Some(np))
110
117
}
111
118
e => {
112
119
returnErr(io::Error::new(
@@ -143,7 +150,9 @@ impl PipeListener {
143
150
}
144
151
145
152
pubfnclose(&self) -> Result<()>{
146
-
Ok(())
153
+
// release the ConnectNamedPipe thread by signaling the event and clean up event handle
154
+
set_event(self.connection_event)?;
155
+
close_handle(self.connection_event)
147
156
}
148
157
}
149
158
@@ -168,15 +177,15 @@ pub struct PipeConnection {
168
177
// "It is safer to use an event object because of the confusion that can occur when multiple simultaneous overlapped operations are performed on the same file, named pipe, or communications device."
169
178
// "In this situation, there is no way to know which operation caused the object's state to be signaled."
0 commit comments