/ tokio Public
net: allow to set linger on TcpSocket #4324
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge.
For now, this is only allowed on TcpStream. This is a problem when one
want to disable lingering (i.e. set it to Duration(0, 0)). Without being
able to set it prior to the connect call, if the connect future is
dropped it would leave sockets in a TIME_WAIT state.
We need to be able to disable lingering on the socket. Otherwise if we drop the connect call, close will cause the socket to move to TIME_WAIT which is a problem for us.
SO_LINGER is a socket option (https://man7.org/linux/man-pages/man7/socket.7.html), expose it as such similar to what is done for buffer sizes for example. I left the possibility to do that on the connected stream as well
Note that I reused the same comments than in TcpStream for consistency. I found that the last part  is a bit confusing but I thought that was better to keep that consistent.
 "If SO_LINGER is not specified, and the socket is closed, the system handles the call in a way that allows the process to continue as quickly as possible."