1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-23 18:45:07 +00:00

Kernel: Try to retransmit lost TCP packets

Previously we didn't retransmit lost TCP packets which would cause
connections to hang if packets were lost. Also we now time out
TCP connections after a number of retransmission attempts.
This commit is contained in:
Gunnar Beutner 2021-05-13 10:49:10 +02:00 committed by Andreas Kling
parent 9daec809b7
commit 08aa3a91e3
3 changed files with 101 additions and 16 deletions

View file

@ -30,6 +30,7 @@ static void handle_udp(const IPv4Packet&, const Time& packet_timestamp);
static void handle_tcp(const IPv4Packet&, const Time& packet_timestamp);
static void send_delayed_tcp_ack(RefPtr<TCPSocket> socket);
static void flush_delayed_tcp_acks();
static void retransmit_tcp_packets();
static Thread* network_task = nullptr;
static HashTable<RefPtr<TCPSocket>>* delayed_ack_sockets;
@ -90,6 +91,7 @@ void NetworkTask_main(void*)
for (;;) {
flush_delayed_tcp_acks();
retransmit_tcp_packets();
size_t packet_size = dequeue_packet(buffer, buffer_size, packet_timestamp);
if (!packet_size) {
auto timeout_time = Time::from_milliseconds(500);
@ -606,4 +608,21 @@ void handle_tcp(const IPv4Packet& ipv4_packet, const Time& packet_timestamp)
}
}
void retransmit_tcp_packets()
{
// We must keep the sockets alive until after we've unlocked the hash table
// in case retransmit_packets() realizes that it wants to close the socket.
NonnullRefPtrVector<TCPSocket, 16> sockets;
{
Locker locker(TCPSocket::sockets_for_retransmit().lock(), LockMode::Shared);
for (auto& socket : TCPSocket::sockets_for_retransmit().resource())
sockets.append(*socket);
}
for (auto& socket : sockets) {
Locker socket_locker(socket.lock());
socket.retransmit_packets();
}
}
}