-const int maxBufferSize = 64 * 1024 * 1024; // protect us from zip bombs
-const int ioBufferSize = 64 * 1024; // chunk size for inflate/deflate; should not be too large as we preallocate that space!
+const int maxBufferSize = 64 * 1024 * 1024; // protect us from zip bombs
+const int ioBufferSize = 64 * 1024; // chunk size for inflate/deflate; should not be too large as we preallocate that space!
- connect(socket, SIGNAL(readyRead()), SLOT(readData()));
+ connect(socket, &QIODevice::readyRead, this, &Compressor::readData);
return;
}
// It's possible that more data has already arrived during the handshake, so readyRead() wouldn't be triggered.
// However, we want to give RemotePeer a chance to connect to our signals, so trigger this asynchronously.
if (socket->bytesAvailable())
return;
}
// It's possible that more data has already arrived during the handshake, so readyRead() wouldn't be triggered.
// However, we want to give RemotePeer a chance to connect to our signals, so trigger this asynchronously.
if (socket->bytesAvailable())
- _inputBuffer.reserve(ioBufferSize); // pre-allocate space
- _outputBuffer.resize(ioBufferSize); // not a typo; we never change the size of this buffer anyway (we *do* for _inputBuffer!)
+ _inputBuffer.reserve(ioBufferSize); // pre-allocate space
+ _outputBuffer.resize(ioBufferSize); // not a typo; we never change the size of this buffer anyway (we *do* for _inputBuffer!)
// If there's still data left in the socket buffer, make sure to schedule a read
if (_socket->bytesAvailable())
// If there's still data left in the socket buffer, make sure to schedule a read
if (_socket->bytesAvailable())
// The usual usage pattern is to write a blocksize first, followed by the actual data.
// By setting NoFlush, one can indicate that the write buffer should not immediately be
// written, which should make things a bit more efficient.
// The usual usage pattern is to write a blocksize first, followed by the actual data.
// By setting NoFlush, one can indicate that the write buffer should not immediately be
// written, which should make things a bit more efficient.
_readBuffer.resize(_readBuffer.size() + ioBufferSize);
_inputBuffer.append(_socket->read(ioBufferSize - _inputBuffer.size()));
_readBuffer.resize(_readBuffer.size() + ioBufferSize);
_inputBuffer.append(_socket->read(ioBufferSize - _inputBuffer.size()));
if (_inflater->avail_in > 0)
memmove(_inputBuffer.data(), _inflater->next_in, _inflater->avail_in);
_inputBuffer.resize(_inflater->avail_in);
if (_inflater->avail_in > 0)
memmove(_inputBuffer.data(), _inflater->next_in, _inflater->avail_in);
_inputBuffer.resize(_inflater->avail_in);
- switch(status) {
- case Z_NEED_DICT:
- case Z_DATA_ERROR:
- case Z_MEM_ERROR:
- case Z_STREAM_ERROR:
- qWarning() << "Error while decompressing stream:" << status;
- emit error(StreamError);
- return;
- case Z_BUF_ERROR:
- // means that we need more input to continue, so this is not an actual error
- return;
- case Z_STREAM_END:
- qWarning() << "Reached end of zlib stream!"; // this should really never happen
- return;
- default:
- // just try to get more out of the stream
- break;
+ switch (status) {
+ case Z_NEED_DICT:
+ case Z_DATA_ERROR:
+ case Z_MEM_ERROR:
+ case Z_STREAM_ERROR:
+ qWarning() << "Error while decompressing stream:" << status;
+ emit error(StreamError);
+ return;
+ case Z_BUF_ERROR:
+ // means that we need more input to continue, so this is not an actual error
+ return;
+ case Z_STREAM_END:
+ qWarning() << "Reached end of zlib stream!"; // this should really never happen
+ return;
+ default:
+ // just try to get more out of the stream
+ break;
_deflater->avail_out = ioBufferSize;
status = deflate(_deflater, Z_PARTIAL_FLUSH);
if (status != Z_OK && status != Z_BUF_ERROR) {
_deflater->avail_out = ioBufferSize;
status = deflate(_deflater, Z_PARTIAL_FLUSH);
if (status != Z_OK && status != Z_BUF_ERROR) {
if (!_socket->write(_outputBuffer.constData(), ioBufferSize - _deflater->avail_out)) {
qWarning() << "Error while writing to socket:" << _socket->errorString();
emit error(DeviceError);
return;
}
if (!_socket->write(_outputBuffer.constData(), ioBufferSize - _deflater->avail_out)) {
qWarning() << "Error while writing to socket:" << _socket->errorString();
emit error(DeviceError);
return;
}
if (_deflater->avail_in > 0) {
qWarning() << "Oops, something weird happened: data still remaining in write buffer!";
if (_deflater->avail_in > 0) {
qWarning() << "Oops, something weird happened: data still remaining in write buffer!";