aboutsummaryrefslogtreecommitdiffstats
path: root/common/rdr/ZlibOutStream.cxx
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2020-05-15 22:49:47 +0200
committerPierre Ossman <ossman@cendio.se>2020-05-21 11:34:22 +0200
commitd7a61c7df39c25945e1aa5f7843e8f3681ed7169 (patch)
tree21d7407a77bba90706bc99667b617d08927ff185 /common/rdr/ZlibOutStream.cxx
parentcf40b83e2330607bab221c33b8f7b5b1885eedb3 (diff)
downloadtigervnc-d7a61c7df39c25945e1aa5f7843e8f3681ed7169.tar.gz
tigervnc-d7a61c7df39c25945e1aa5f7843e8f3681ed7169.zip
Generalise corking to all output streams
The principle can be used in a more general fashion than just TCP streams.
Diffstat (limited to 'common/rdr/ZlibOutStream.cxx')
-rw-r--r--common/rdr/ZlibOutStream.cxx44
1 files changed, 23 insertions, 21 deletions
diff --git a/common/rdr/ZlibOutStream.cxx b/common/rdr/ZlibOutStream.cxx
index 8f7170da..0eb89222 100644
--- a/common/rdr/ZlibOutStream.cxx
+++ b/common/rdr/ZlibOutStream.cxx
@@ -92,10 +92,25 @@ void ZlibOutStream::flush()
#endif
// Force out everything from the zlib encoder
- deflate(Z_SYNC_FLUSH);
+ deflate(corked ? Z_NO_FLUSH : Z_SYNC_FLUSH);
+
+ if (zs->avail_in == 0) {
+ offset += ptr - start;
+ ptr = start;
+ } else {
+ // didn't consume all the data? try shifting what's left to the
+ // start of the buffer.
+ memmove(start, zs->next_in, ptr - zs->next_in);
+ offset += zs->next_in - start;
+ ptr -= zs->next_in - start;
+ }
+}
+
+void ZlibOutStream::cork(bool enable)
+{
+ OutStream::cork(enable);
- offset += ptr - start;
- ptr = start;
+ underlying->cork(enable);
}
void ZlibOutStream::overrun(size_t needed)
@@ -110,24 +125,11 @@ void ZlibOutStream::overrun(size_t needed)
checkCompressionLevel();
while (avail() < needed) {
- zs->next_in = start;
- zs->avail_in = ptr - start;
-
- deflate(Z_NO_FLUSH);
-
- // output buffer not full
-
- if (zs->avail_in == 0) {
- offset += ptr - start;
- ptr = start;
- } else {
- // but didn't consume all the data? try shifting what's left to the
- // start of the buffer.
- vlog.info("z out buf not full, but in data not consumed");
- memmove(start, zs->next_in, ptr - zs->next_in);
- offset += zs->next_in - start;
- ptr -= zs->next_in - start;
- }
+ // use corked to make zlib a bit more efficient since we're not trying
+ // to end the stream here, just make some room
+ corked = true;
+ flush();
+ corked = false;
}
}