From 2c51ff763b90eef0ac9cb2aac1c879020654302f Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Tue, 26 Dec 2023 19:04:11 +0200 Subject: [PATCH] Kernel: Properly report receive window size in sent TCP packets Instead of lying and claiming we always have space left in our receive buffer, actually report the available space. While this doesn't really affect network-bound workloads, it makes a world of difference in cpu/disk-bound ones, like git clones. Resulting in a considerable speed-up, and in some cases making them work at all. (instead of the sender side hanging up the connection due to timeouts) --- Kernel/Net/IPv4Socket.h | 2 ++ Kernel/Net/TCPSocket.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Kernel/Net/IPv4Socket.h b/Kernel/Net/IPv4Socket.h index e9ef4eef59..48d5e3301e 100644 --- a/Kernel/Net/IPv4Socket.h +++ b/Kernel/Net/IPv4Socket.h @@ -90,6 +90,8 @@ protected: static ErrorOr> try_create_receive_buffer(); void drop_receive_buffer(); + size_t available_space_in_receive_buffer() const { return m_receive_buffer ? m_receive_buffer->space_for_writing() : 0; } + private: virtual bool is_ipv4() const override { return true; } diff --git a/Kernel/Net/TCPSocket.cpp b/Kernel/Net/TCPSocket.cpp index fbf69fae05..1e5caa2599 100644 --- a/Kernel/Net/TCPSocket.cpp +++ b/Kernel/Net/TCPSocket.cpp @@ -260,7 +260,7 @@ ErrorOr TCPSocket::send_tcp_packet(u16 flags, UserOrKernelBuffer const* pa VERIFY(local_port()); tcp_packet.set_source_port(local_port()); tcp_packet.set_destination_port(peer_port()); - tcp_packet.set_window_size(NumericLimits::max()); + tcp_packet.set_window_size(min(available_space_in_receive_buffer(), NumericLimits::max())); tcp_packet.set_sequence_number(m_sequence_number); tcp_packet.set_data_offset(tcp_header_size / sizeof(u32)); tcp_packet.set_flags(flags);