Skip to content
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/sys/windows/named_pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,21 @@ fn read_done(status: &OVERLAPPED_ENTRY, events: Option<&mut Vec<Event>>) {
// Move from the `Pending` to `Ok` state.
let mut io = me.io.lock().unwrap();
let mut buf = match mem::replace(&mut io.read, State::None) {
State::Ok(buf, pos) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this can happen but it seems safe to just handle it. If read_done is called twice in a row, this could possibly trigger but I don't know enough about the internals here and how Windows handles this to say for sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All we do further down is notify that the buffer needs to be consumed. If we are still in Ok, I am guessing this means it hasn't been consumed yet.

io.read = State::Ok(buf, pos);

// Flag readiness that we have undelivered data to be read.
io.notify_readable(&me, events);
return;
}
State::Pending(buf, _) => buf,
State::Err(e) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

io.read = State::Err(e);

// Flag readiness that the error needs to be delivered.
io.notify_readable(&me, events);
return;
}
_ => unreachable!(),
};
unsafe {
Expand Down Expand Up @@ -909,13 +923,21 @@ fn write_done(status: &OVERLAPPED_ENTRY, events: Option<&mut Vec<Event>>) {
let mut io = me.io.lock().unwrap();
let (buf, pos) = match mem::replace(&mut io.write, State::None) {
// `Ok` here means, that the operation was completed immediately
// `bytes_transferred` is already reported to a client
// `bytes_transferred` is already reported to a client.
// Hence, we don't reset the state to `Ok` but leave it in `None`.
State::Ok(..) => {
io.notify_writable(&me, events);
return;
}
State::Pending(buf, pos) => (buf, pos),
_ => unreachable!(),
State::Err(e) => {
io.write = State::Err(e);

// Flag readiness that the error needs to be delivered.
io.notify_writable(&me, events);
return;
}
State::None => unreachable!(),
};

unsafe {
Expand Down