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)
This commit is contained in:
Idan Horowitz 2023-12-26 19:04:11 +02:00 committed by Andreas Kling
parent 69f88c9a64
commit 2c51ff763b
Notes: sideshowbarker 2024-07-17 03:35:16 +09:00
2 changed files with 3 additions and 1 deletions

View file

@ -90,6 +90,8 @@ protected:
static ErrorOr<NonnullOwnPtr<DoubleBuffer>> 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; }

View file

@ -260,7 +260,7 @@ ErrorOr<void> 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<u16>::max());
tcp_packet.set_window_size(min(available_space_in_receive_buffer(), NumericLimits<u16>::max()));
tcp_packet.set_sequence_number(m_sequence_number);
tcp_packet.set_data_offset(tcp_header_size / sizeof(u32));
tcp_packet.set_flags(flags);