+ _deflater->next_in = reinterpret_cast<unsigned char*>(_writeBuffer.data());
+ _deflater->avail_in = _writeBuffer.size();
+
+ int status;
+ do {
+ _deflater->next_out = reinterpret_cast<unsigned char*>(_outputBuffer.data());
+ _deflater->avail_out = ioBufferSize;
+ status = deflate(_deflater, Z_PARTIAL_FLUSH);
+ if (status != Z_OK && status != Z_BUF_ERROR) {
+ qWarning() << "Error while compressing stream:" << status;
+ emit error(StreamError);
+ return;
+ }
+
+ if (_deflater->avail_out == static_cast<unsigned int>(ioBufferSize))
+ continue; // nothing to write here
+
+ if (!_socket->write(_outputBuffer.constData(), ioBufferSize - _deflater->avail_out)) {
+ qWarning() << "Error while writing to socket:" << _socket->errorString();
+ emit error(DeviceError);
+ return;
+ }
+ } while (_deflater->avail_out == 0); // the output buffer being full is the only reason we should have to loop here!
+
+ if (_deflater->avail_in > 0) {
+ qWarning() << "Oops, something weird happened: data still remaining in write buffer!";
+ emit error(StreamError);
+ }
+
+ _writeBuffer.resize(0);
+
+ // qDebug() << "deflate in:" << _deflater->total_in << "out:" << _deflater->total_out << "ratio:" << (double)_deflater->total_out/_deflater->total_in;
+}