Skip to content

Commit

Permalink
Fixed leaked sock states, issue tokio-rs#1146. Changes after review, …
Browse files Browse the repository at this point in the history
…keep things simple in the Drop impl.

Signed-off-by: Daniel Tacalau <dst4096@gmail.com>
  • Loading branch information
dtacalau committed Nov 25, 2019
1 parent 4ba341e commit 92e037e
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/sys/windows/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,30 @@ unsafe impl Sync for SelectorInner {}
impl Drop for SelectorInner {
fn drop(&mut self) {
loop {
let mut events = Events::with_capacity(1024);
let _ = self.select(&mut events, Some(std::time::Duration::from_millis(0)));
if events.events.len() < 1024 {
let events_num: usize;
let mut statuses: [CompletionStatus; 1024] = [CompletionStatus::zero(); 1024];

let result = self
.cp
.get_many(&mut statuses, Some(std::time::Duration::from_millis(0)));
match result {
Ok(iocp_events) => {
events_num = iocp_events.iter().len();
for iocp_event in iocp_events.iter() {
if iocp_event.overlapped().is_null() == false {
// drain sock state to release memory of Arc reference
let _sock_state = from_overlapped(iocp_event.overlapped());
}
}
}

Err(_) => {
break;
}
}

if events_num < 1024 {
// continue looping until all completion statuses have been drained
break;
}
}
Expand Down

0 comments on commit 92e037e

Please sign in to comment.