mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-02-20 22:55:03 +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:
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user