Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow limiting download speed #15

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions utp_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,12 @@ struct UTPSocket {
return opt_rcvbuf > numbuf ? opt_rcvbuf - numbuf : 0;
}

// check if the read buffer have space to accept this payload
bool can_buffer_payload(size_t len)
{
return get_rcv_window() >= len;
}

// Test if we're ready to decay max_window
// XXX this breaks when spaced by > INT_MAX/2, which is 49
// days; the failure mode in that case is we do an extra decay
Expand Down Expand Up @@ -2344,9 +2350,16 @@ size_t utp_process_incoming(UTPSocket *conn, const byte *packet, size_t len, boo
// sequence numbers past this
}

// Can our read buffer hold this packet payload?
if (!conn->can_buffer_payload(packet_end - data))
{
return 0;
}

// Getting an in-order packet?
if (seqnr == 0) {
size_t count = packet_end - data;

if (count > 0 && conn->state != CS_FIN_SENT) {

#if UTP_DEBUG_LOGGING
Expand Down