-
Notifications
You must be signed in to change notification settings - Fork 41
Clean shutdown of TCP sockets #73
Comments
Thanks for the report! I agree it's a little unfortunate the naming conflict between The implementation for TCP to not actually do anything on shutdown was actually pretty deliberate, AFAIK there's not really a well established canonical way to shutdown a TCP socket, I think it's mostly just "some applications do it, most probably dont" |
Just wondering why implementation of shutdown for AsyncWrite for TcpStream is just dummy - this is I believe current implementtaion: impl<'a> AsyncWrite for &'a TcpStream {
fn shutdown(&mut self) -> Poll<(), io::Error> {
Ok(().into())
} Why we cannot provide rather default implementation that is on proxy example - eg. call stream shutdown with Shutdown::Write? For proxy example new struct had to be created (worth app. 20 lines of code) just to implement this code. My reasoning why to include default implementations is:
And indeed name conflict can be bit confusing. |
@izderadicka the intention of |
Closing this issue in favor of #80. |
I just implemented clean connection shutdown again in Thrussh (since I moved it to Tokio a few months ago).
The Tokio interface for that was not totally easy. Here are things I'd like to have:
I needed to call
.shutdown(Shutdown::Both)
onTcpStream
. This works as long as the underlying connection is indeed aTcpStream
, but what if I want to run the connection in a buffer for testing? I wrote a trait calledTcp
, containing a methodshutdown
that does that, but I guess there could be something more generic.There is a name conflict on
shutdown
methods inTcpStream
andAsyncWrite
. Not a big deal for me, but on a larger codebase, it might be burdensome. How about having theshutdown
method ofTcpStream
not takeself
, but instead having to calltokio_core::net::TcpStream::shutdown(&mut stream)
?Or there might be something more general: I don't know whether "TCP shutdown" should be called from within the
AsyncWrite::shutdown
method ofTcpStream
, because there might be a number of parameters to a proper TCP shutdown, in some cases. But I guess it is fairly standard to send ashutdown
and waiting for aread
to return 0, so why not have another type calledCleanShutdownTcpStream
whoseAsync::shutdown
method does exactly that?The text was updated successfully, but these errors were encountered: