Kernel: Switch IPv4Socket receive queue to SinglyLinkedListWithCount<T>

Avoid walking the packet queue, instead use a linked list with a count.
This commit is contained in:
Brian Gianforcaro 2020-08-04 21:35:30 -07:00 committed by Andreas Kling
parent efb0805d8e
commit f3eb7db422
Notes: sideshowbarker 2024-07-19 04:18:23 +09:00
2 changed files with 6 additions and 7 deletions

View file

@ -285,7 +285,7 @@ KResultOr<size_t> IPv4Socket::receive_packet_buffered(FileDescription& descripti
packet = m_receive_queue.take_first();
m_can_read = !m_receive_queue.is_empty();
#ifdef IPV4_SOCKET_DEBUG
dbg() << "IPv4Socket(" << this << "): recvfrom without blocking " << packet.data.value().size() << " bytes, packets in queue: " << m_receive_queue.size_slow();
dbg() << "IPv4Socket(" << this << "): recvfrom without blocking " << packet.data.value().size() << " bytes, packets in queue: " << m_receive_queue.size();
#endif
}
}
@ -311,7 +311,7 @@ KResultOr<size_t> IPv4Socket::receive_packet_buffered(FileDescription& descripti
packet = m_receive_queue.take_first();
m_can_read = !m_receive_queue.is_empty();
#ifdef IPV4_SOCKET_DEBUG
dbg() << "IPv4Socket(" << this << "): recvfrom with blocking " << packet.data.value().size() << " bytes, packets in queue: " << m_receive_queue.size_slow();
dbg() << "IPv4Socket(" << this << "): recvfrom with blocking " << packet.data.value().size() << " bytes, packets in queue: " << m_receive_queue.size();
#endif
}
ASSERT(packet.data.has_value());
@ -380,8 +380,7 @@ bool IPv4Socket::did_receive(const IPv4Address& source_address, u16 source_port,
m_receive_buffer.write(m_scratch_buffer.value().data(), nreceived_or_error.value());
m_can_read = !m_receive_buffer.is_empty();
} else {
// FIXME: Maybe track the number of packets so we don't have to walk the entire packet queue to count them..
if (m_receive_queue.size_slow() > 2000) {
if (m_receive_queue.size() > 2000) {
dbg() << "IPv4Socket(" << this << "): did_receive refusing packet since queue is full.";
return false;
}
@ -393,7 +392,7 @@ bool IPv4Socket::did_receive(const IPv4Address& source_address, u16 source_port,
if (buffer_mode() == BufferMode::Bytes)
dbg() << "IPv4Socket(" << this << "): did_receive " << packet_size << " bytes, total_received=" << m_bytes_received;
else
dbg() << "IPv4Socket(" << this << "): did_receive " << packet_size << " bytes, total_received=" << m_bytes_received << ", packets in queue: " << m_receive_queue.size_slow();
dbg() << "IPv4Socket(" << this << "): did_receive " << packet_size << " bytes, total_received=" << m_bytes_received << ", packets in queue: " << m_receive_queue.size();
#endif
return true;
}

View file

@ -27,7 +27,7 @@
#pragma once
#include <AK/HashMap.h>
#include <AK/SinglyLinkedList.h>
#include <AK/SinglyLinkedListWithCount.h>
#include <Kernel/DoubleBuffer.h>
#include <Kernel/KBuffer.h>
#include <Kernel/Lock.h>
@ -122,7 +122,7 @@ private:
Optional<KBuffer> data;
};
SinglyLinkedList<ReceivedPacket> m_receive_queue;
SinglyLinkedListWithCount<ReceivedPacket> m_receive_queue;
DoubleBuffer m_receive_buffer;