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
88
-
let np = self.new_instance().unwrap();
89
-
let ol = Overlapped::new();
85
+
let instance = self.new_instance()?;
86
+
let np = matchPipeConnection::new(instance){
87
+
Ok(np) => np,
88
+
Err(e) => {
89
+
returnErr(io::Error::new(
90
+
io::ErrorKind::Other,
91
+
format!("failed to create new pipe instance: {:?}", e),
92
+
));
93
+
}
94
+
};
95
+
96
+
let ol = Overlapped::new_with_event(self.connection_event);
90
97
91
98
trace!("listening for connection");
92
-
let result = unsafe{ConnectNamedPipe(np, ol.as_mut_ptr())};
99
+
let result = unsafe{ConnectNamedPipe(np.named_pipe, ol.as_mut_ptr())};
93
100
if result != 0{
94
101
returnErr(io::Error::last_os_error());
95
102
}
96
103
97
104
match io::Error::last_os_error(){
98
105
e if e.raw_os_error() == Some(ERROR_IO_PENDINGasi32) => {
99
106
letmut bytes_transfered = 0;
100
-
let res = unsafe{GetOverlappedResult(np, ol.as_mut_ptr(),&mut bytes_transfered,WAIT_FOR_EVENT)};
107
+
let res = unsafe{GetOverlappedResult(np.named_pipe, ol.as_mut_ptr(),&mut bytes_transfered,WAIT_FOR_EVENT)};
101
108
match res {
102
109
0 => {
103
110
returnErr(io::Error::last_os_error());
104
111
}
105
112
_ => {
106
-
Ok(Some(PipeConnection::new(np)))
113
+
Ok(Some(np))
107
114
}
108
115
}
109
116
}
110
117
e if e.raw_os_error() == Some(ERROR_PIPE_CONNECTEDasi32) => {
111
-
Ok(Some(PipeConnection::new(np)))
118
+
Ok(Some(np))
112
119
}
113
120
e => {
114
121
returnErr(io::Error::new(
@@ -145,7 +152,9 @@ impl PipeListener {
145
152
}
146
153
147
154
pubfnclose(&self) -> Result<()>{
148
-
Ok(())
155
+
// release the ConnectNamedPipe thread by signaling the event and clean up event handle
156
+
set_event(self.connection_event)?;
157
+
close_handle(self.connection_event)
149
158
}
150
159
}
151
160
@@ -170,15 +179,15 @@ pub struct PipeConnection {
170
179
// "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."
171
180
// "In this situation, there is no way to know which operation caused the object's state to be signaled."
0 commit comments