Skip to content

Commit

Permalink
Properly restore cork state when changed
Browse files Browse the repository at this point in the history
These streams both need to change the corking state temporarily, but it
is important it is restored to the previous state or things might get
messed up.

For the zlib stream it would just leave things uncorked, which still
works but is less efficient.

But for the TLS stream it might make things very unresponsive as the
corking might be left on permanently, delaying packets indefinitely.
  • Loading branch information
CendioOssman committed Jun 28, 2022
1 parent 8e6e77f commit ff9ccc2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 6 additions & 1 deletion common/rdr/TLSOutStream.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,18 @@ void TLSOutStream::cork(bool enable)

void TLSOutStream::overrun(size_t needed)
{
bool oldCorked;

if (needed > bufSize)
throw Exception("TLSOutStream overrun: buffer size exceeded");

// A cork might prevent the flush, so disable it temporarily
oldCorked = corked;
corked = false;

flush();
corked = true;

corked = oldCorked;
}

size_t TLSOutStream::writeTLS(const U8* data, size_t length)
Expand Down
8 changes: 7 additions & 1 deletion common/rdr/ZlibOutStream.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,17 @@ void ZlibOutStream::overrun(size_t needed)
checkCompressionLevel();

while (avail() < needed) {
bool oldCorked;

// use corked to make zlib a bit more efficient since we're not trying
// to end the stream here, just make some room

oldCorked = corked;
corked = true;

flush();
corked = false;

corked = oldCorked;
}
}

Expand Down

0 comments on commit ff9ccc2

Please sign in to comment.