Skip to content

Commit

Permalink
fixed windows TFO by using tokio try_write_io
Browse files Browse the repository at this point in the history
  • Loading branch information
zonyitoo committed Jul 6, 2021
1 parent 0f942ea commit 3974caa
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions crates/shadowsocks/src/net/sys/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ impl AsyncWrite for TcpStream {
TcpStreamState::FastOpenConnecting(ref mut overlapped) => {
let stream = inner.get_mut();

let n = ready!(stream.poll_write_io(cx, || {
ready!(stream.poll_write_ready(cx))?;

let write_result = stream.try_write_io(|| {
unsafe {
let sock = stream.as_raw_socket() as SOCKET;

Expand Down Expand Up @@ -320,11 +322,19 @@ impl AsyncWrite for TcpStream {
Err(io::Error::from_raw_os_error(err))
}
}
}))?;
});

// Connect successfully with fast open
*state = TcpStreamState::Connected;
return Ok(n).into();
match write_result {
Ok(n) => {
// Connect successfully with fast open
*state = TcpStreamState::Connected;
return Ok(n).into();
}
Err(ref err) if err.kind() == ErrorKind::WouldBlock => {
// Wait again for writable event.
}
Err(err) => return Err(err).into(),
}
}
}
}
Expand Down

0 comments on commit 3974caa

Please sign in to comment.