-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clearing TcpStream's writable event #3873
Comments
Which solution you prefer? @Darksonn I could make a PR. |
Or maybe, add pub fn try_io<R>(&self,
cx: &mut Context<'_>,
interest: Interest,
f: impl FnOnce() -> io::Result<R>) -> io::Result<()> {
self.io
.registration()
.try_io(interest, f)
} Or pub fn poll_write_io<R>(
&self,
cx: &mut Context<'_>,
f: impl FnMut() -> io::Result<R>,
) -> Poll<io::Result<R>> {
self.io.registration().poll_write_io(cx, f)
} |
Adding a method to clear readiness is tricky as it opens up the API to potential races. An event may be received after the last time readiness is observed and the call to clear readiness, resulting in a lost event. This is why AsyncFd returns a readiness guard and that is used to clear readiness (the guard prevents the race). For this case, I am wondering if exposing Thoughts @Darksonn ? |
A |
With let mut connecting = false;
let result = stream.try_io(Interest::writable(), || {
let ret = libc::sendto(sockfd, buf.as_ptr(), buf.len(), MSG_FASTOPEN, saddr.as_ptr(), saddr.len());
if ret < 0 {
let err = Error::last_os_error();
if (err.kind() != ErrorKind::WouldBlock) {
if let Some(libc::EINPROGRESS) = err.raw_os_error() {
connecting = true;
Err(ErrorKind::WouldBlock.into())
} else {
Err(err)
}
} else {
Err(err)
}
} else {
Ok(ret as usize)
}
});
// .. Handling result
if connecting {
ready!(stream.poll_write_ready());
} |
Is your feature request related to a problem? Please describe.
I am trying to make
TcpStream
to support TCP Fast Open. On Linux and FreeBSD, TFO is enabled with:TCP_FASTOPEN
sockopt on the socketsendto
with the first packetsend
as the normal TCP socketsSince
TcpStream::poll_write
actually callssend
, so I have to manually do:poll_write_ready
sendto
, and checkEAGAIN
orEINPROGRESS
errno == EINPROGRESS
, I have to clear the write ready state and callpoll_write_ready
againDescribe the solution you'd like
clear_write_ready
to clear the writable state of the internalio
poll_write_ready
returns aWriteReadyGuard
just likeAsyncFd
Describe alternatives you've considered
There shouldn't be an alternative way to make it possible.
Additional context
ref shadowsocks/shadowsocks-rust#555
The text was updated successfully, but these errors were encountered: