mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:38:12 +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:
parent
f4d3c54c12
commit
0ccef94a49
3 changed files with 19 additions and 1 deletions
|
@ -248,6 +248,9 @@ KResultOr<size_t> IPv4Socket::sendto(OpenFileDescription&, const UserOrKernelBuf
|
|||
KResultOr<size_t> IPv4Socket::receive_byte_buffered(OpenFileDescription& description, UserOrKernelBuffer& buffer, size_t buffer_length, int flags, Userspace<sockaddr*>, Userspace<socklen_t*>)
|
||||
{
|
||||
MutexLocker locker(mutex());
|
||||
|
||||
VERIFY(m_receive_buffer);
|
||||
|
||||
if (m_receive_buffer->is_empty()) {
|
||||
if (protocol_is_disconnected())
|
||||
return 0;
|
||||
|
@ -408,6 +411,8 @@ bool IPv4Socket::did_receive(const IPv4Address& source_address, u16 source_port,
|
|||
auto packet_size = packet.size();
|
||||
|
||||
if (buffer_mode() == BufferMode::Bytes) {
|
||||
VERIFY(m_receive_buffer);
|
||||
|
||||
size_t space_in_receive_buffer = m_receive_buffer->space_for_writing();
|
||||
if (packet_size > space_in_receive_buffer) {
|
||||
dbgln("IPv4Socket({}): did_receive refusing packet since buffer is full.", this);
|
||||
|
@ -764,4 +769,9 @@ void IPv4Socket::set_can_read(bool value)
|
|||
evaluate_block_conditions();
|
||||
}
|
||||
|
||||
void IPv4Socket::drop_receive_buffer()
|
||||
{
|
||||
m_receive_buffer = nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue