Index: remoting/base/compressor_zlib.cc |
diff --git a/remoting/base/compressor_zlib.cc b/remoting/base/compressor_zlib.cc |
index ae5b388718fa6e7eb09abca9984382a8af3f73b5..6f7007319685f87f04d89a5f79ea0b4244ba26ed 100644 |
--- a/remoting/base/compressor_zlib.cc |
+++ b/remoting/base/compressor_zlib.cc |
@@ -37,7 +37,8 @@ CompressorZlib::~CompressorZlib() { |
bool CompressorZlib::Process(const uint8* input_data, int input_size, |
uint8* output_data, int output_size, |
- int* consumed, int* written) { |
+ CompressorFlush flush, int* consumed, |
+ int* written) { |
DCHECK_GT(output_size, 0); |
// Setup I/O parameters. |
@@ -46,7 +47,18 @@ bool CompressorZlib::Process(const uint8* input_data, int input_size, |
stream_->avail_out = output_size; |
stream_->next_out = (Bytef*)output_data; |
- int ret = deflate(stream_.get(), input_size ? Z_NO_FLUSH : Z_FINISH); |
+ int z_flush = 0; |
+ if (flush == CompressorSyncFlush) { |
+ z_flush = Z_SYNC_FLUSH; |
+ } else if (flush == CompressorFinish) { |
+ z_flush = Z_FINISH; |
+ } else if (flush == CompressorNoFlush) { |
+ z_flush = Z_NO_FLUSH; |
+ } else { |
+ NOTREACHED() << "Unsupported flush mode"; |
+ } |
+ |
+ int ret = deflate(stream_.get(), z_flush); |
if (ret == Z_STREAM_ERROR) { |
NOTREACHED() << "zlib compression failed"; |
} |
@@ -54,9 +66,19 @@ bool CompressorZlib::Process(const uint8* input_data, int input_size, |
*consumed = input_size - stream_->avail_in; |
*written = output_size - stream_->avail_out; |
- // Return true when we get Z_BUF_ERROR, this way we can feed more data |
- // to zlib. |
- return ret == Z_OK || ret == Z_BUF_ERROR; |
+ // If |ret| equals Z_STREAM_END we have reached the end of stream. |
+ // If |ret| equals Z_BUF_ERROR we have the end of the synchronication point. |
+ // For these two cases we need to stop compressing. |
+ if (ret == Z_OK) { |
+ return true; |
+ } else if (ret == Z_STREAM_END) { |
+ return false; |
+ } else if (ret == Z_BUF_ERROR) { |
+ return stream_->avail_out == 0; |
+ } else { |
+ NOTREACHED() << "Unexpected zlib error: " << ret; |
+ return false; |
+ } |
} |
} // namespace remoting |