summaryrefslogtreecommitdiff
path: root/Kernel/Net/IPv4Socket.cpp
diff options
context:
space:
mode:
authorsin-ack <sin-ack@users.noreply.github.com>2021-09-16 00:15:36 +0000
committerAndreas Kling <kling@serenityos.org>2021-09-16 16:50:23 +0200
commit0ccef94a496300becc4dd6e5a2bde3c7fe12dc68 (patch)
tree3f113c616b540474188bb60e4eb26ff30807fdfb /Kernel/Net/IPv4Socket.cpp
parentf4d3c54c12f64edec0eeb1395c6531787dbd738e (diff)
downloadserenity-0ccef94a496300becc4dd6e5a2bde3c7fe12dc68.zip
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.
Diffstat (limited to 'Kernel/Net/IPv4Socket.cpp')
-rw-r--r--Kernel/Net/IPv4Socket.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp
index 3f2704ec29..83b3d794f7 100644
--- a/Kernel/Net/IPv4Socket.cpp
+++ b/Kernel/Net/IPv4Socket.cpp
@@ -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;
+}
+
}