-
-
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
WriteHalf<TcpStream>::shutdown won't shutdown the TcpStream #852
Comments
I have the same issue where it's not possible to shutdown the For now I have added a workaround in my code using wrapping struct but I think it should be fixed in the Tokio. struct WrappedTcpStream(TcpStream);
impl Read for WrappedTcpStream {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.0.read(buf)
}
}
impl Write for WrappedTcpStream {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.0.write(buf)
}
fn flush(&mut self) -> io::Result<()> {
self.0.flush()
}
}
impl AsyncRead for WrappedTcpStream {
unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [u8]) -> bool {
self.0.prepare_uninitialized_buffer(buf)
}
fn read_buf<B: BufMut>(&mut self, buf: &mut B) -> Poll<usize, io::Error> {
self.0.read_buf(buf)
}
}
impl AsyncWrite for WrappedTcpStream {
fn shutdown(&mut self) -> Poll<(), io::Error> {
self.0.shutdown(Shutdown::Write)?;
Ok(().into())
}
fn write_buf<B: Buf>(&mut self, buf: &mut B) -> Poll<usize, io::Error> {
self.0.write_buf(buf)
}
} And then in the code: let (reader, writer) = WrappedTcpStream(stream).split();
....
tokio::io::shutdown(writer) |
Yes, I agree this is very annoying. First, the The second problem is accessing |
This just bit me today (though I was just using a bare TcpStream, not wrapped in a WriteHalf). I ended up just wrapping the TcpStream object and hand implemented AsyncRead/AsyncWrite by delegating the AsyncRead/AsyncWrite to the TcpStream implementation except in the case of the shutdown method where I explicitly called TcpStream::shutdown(::std::net::Shutdown::Write) to force the write side to be shutdown. |
Version
tokio 0.1.14
Platform
Linux archlinux 4.19.13-1-lts #1 SMP Sun Dec 30 07:38:47 CET 2018 x86_64 GNU/Linux
Subcrates
tokio-tcp
Description
I'm trying to implement a TCP proxy and I know there is an example. I noticed that calling the shutdown method of
WriteHalf<TcpStream>
does nothing. I find this after some research:My question is that why this shutdown does nothing instead of calling TcpStream::shutdown(self, Shutdown::Write) since it allow us write something like this:
The text was updated successfully, but these errors were encountered: