From 6393f97bfb95e4c9817e7e5a04f88dfb947667fc Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Mon, 20 Sep 2021 19:10:43 +0200 Subject: [PATCH] Erase backpressure in steps of 1/32th --- src/AsyncSocketData.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/AsyncSocketData.h b/src/AsyncSocketData.h index 94575d8..b72b2c1 100644 --- a/src/AsyncSocketData.h +++ b/src/AsyncSocketData.h @@ -22,9 +22,6 @@ namespace uWS { -/* We erase a minimum of 32kb off the front of the backpressure buffer when draining */ -const int BACKPRESSURE_MINIMAL_ERASE = 32 * 1024; - struct BackPressure { std::string buffer; unsigned int pendingRemoval = 0; @@ -38,7 +35,8 @@ struct BackPressure { } void erase(unsigned int length) { pendingRemoval += length; - if (pendingRemoval > BACKPRESSURE_MINIMAL_ERASE || !(buffer.length() - pendingRemoval)) { + /* Always erase a minimum of 1/32th the current backpressure */ + if (pendingRemoval > (buffer.length() >> 5)) { buffer.erase(0, pendingRemoval); pendingRemoval = 0; }