Skip to content

Commit 3974caa

Browse files
committed
fixed windows TFO by using tokio try_write_io
1 parent 0f942ea commit 3974caa

File tree

1 file changed

+15
-5
lines changed
  • crates/shadowsocks/src/net/sys/windows

1 file changed

+15
-5
lines changed

crates/shadowsocks/src/net/sys/windows/mod.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,9 @@ impl AsyncWrite for TcpStream {
283283
TcpStreamState::FastOpenConnecting(ref mut overlapped) => {
284284
let stream = inner.get_mut();
285285

286-
let n = ready!(stream.poll_write_io(cx, || {
286+
ready!(stream.poll_write_ready(cx))?;
287+
288+
let write_result = stream.try_write_io(|| {
287289
unsafe {
288290
let sock = stream.as_raw_socket() as SOCKET;
289291

@@ -320,11 +322,19 @@ impl AsyncWrite for TcpStream {
320322
Err(io::Error::from_raw_os_error(err))
321323
}
322324
}
323-
}))?;
325+
});
324326

325-
// Connect successfully with fast open
326-
*state = TcpStreamState::Connected;
327-
return Ok(n).into();
327+
match write_result {
328+
Ok(n) => {
329+
// Connect successfully with fast open
330+
*state = TcpStreamState::Connected;
331+
return Ok(n).into();
332+
}
333+
Err(ref err) if err.kind() == ErrorKind::WouldBlock => {
334+
// Wait again for writable event.
335+
}
336+
Err(err) => return Err(err).into(),
337+
}
328338
}
329339
}
330340
}

0 commit comments

Comments
 (0)