mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 14:47:34 +00:00
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:
parent
efb0805d8e
commit
f3eb7db422
2 changed files with 6 additions and 7 deletions
|
@ -285,7 +285,7 @@ KResultOr<size_t> IPv4Socket::receive_packet_buffered(FileDescription& descripti
|
||||||
packet = m_receive_queue.take_first();
|
packet = m_receive_queue.take_first();
|
||||||
m_can_read = !m_receive_queue.is_empty();
|
m_can_read = !m_receive_queue.is_empty();
|
||||||
#ifdef IPV4_SOCKET_DEBUG
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -311,7 +311,7 @@ KResultOr<size_t> IPv4Socket::receive_packet_buffered(FileDescription& descripti
|
||||||
packet = m_receive_queue.take_first();
|
packet = m_receive_queue.take_first();
|
||||||
m_can_read = !m_receive_queue.is_empty();
|
m_can_read = !m_receive_queue.is_empty();
|
||||||
#ifdef IPV4_SOCKET_DEBUG
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
ASSERT(packet.data.has_value());
|
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_receive_buffer.write(m_scratch_buffer.value().data(), nreceived_or_error.value());
|
||||||
m_can_read = !m_receive_buffer.is_empty();
|
m_can_read = !m_receive_buffer.is_empty();
|
||||||
} else {
|
} 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() > 2000) {
|
||||||
if (m_receive_queue.size_slow() > 2000) {
|
|
||||||
dbg() << "IPv4Socket(" << this << "): did_receive refusing packet since queue is full.";
|
dbg() << "IPv4Socket(" << this << "): did_receive refusing packet since queue is full.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -393,7 +392,7 @@ bool IPv4Socket::did_receive(const IPv4Address& source_address, u16 source_port,
|
||||||
if (buffer_mode() == BufferMode::Bytes)
|
if (buffer_mode() == BufferMode::Bytes)
|
||||||
dbg() << "IPv4Socket(" << this << "): did_receive " << packet_size << " bytes, total_received=" << m_bytes_received;
|
dbg() << "IPv4Socket(" << this << "): did_receive " << packet_size << " bytes, total_received=" << m_bytes_received;
|
||||||
else
|
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
|
#endif
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
#include <AK/SinglyLinkedList.h>
|
#include <AK/SinglyLinkedListWithCount.h>
|
||||||
#include <Kernel/DoubleBuffer.h>
|
#include <Kernel/DoubleBuffer.h>
|
||||||
#include <Kernel/KBuffer.h>
|
#include <Kernel/KBuffer.h>
|
||||||
#include <Kernel/Lock.h>
|
#include <Kernel/Lock.h>
|
||||||
|
@ -122,7 +122,7 @@ private:
|
||||||
Optional<KBuffer> data;
|
Optional<KBuffer> data;
|
||||||
};
|
};
|
||||||
|
|
||||||
SinglyLinkedList<ReceivedPacket> m_receive_queue;
|
SinglyLinkedListWithCount<ReceivedPacket> m_receive_queue;
|
||||||
|
|
||||||
DoubleBuffer m_receive_buffer;
|
DoubleBuffer m_receive_buffer;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue