1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:04:57 +00:00

Kernel: Drop the receive buffer when socket enters the TimeWait state

The TimeWait state is intended to prevent another socket from taking the
address tuple in case any packets are still in transit after the final
close. Since this state never delivers packets to userspace, it doesn't
make sense to keep the receive buffer around.
This commit is contained in:
sin-ack 2021-09-16 00:15:36 +00:00 committed by Andreas Kling
parent f4d3c54c12
commit 0ccef94a49
3 changed files with 19 additions and 1 deletions

View file

@ -43,6 +43,13 @@ void TCPSocket::set_state(State new_state)
[[maybe_unused]] auto rc = set_so_error(KSuccess);
}
if (new_state == State::TimeWait) {
// Once we hit TimeWait, we are only holding the socket in case there
// are packets on the way which we wouldn't want a new socket to get hit
// with, so there's no point in keeping the receive buffer around.
drop_receive_buffer();
}
if (new_state == State::Closed) {
closing_sockets().with_exclusive([&](auto& table) {
table.remove(tuple());