QSslSocketBackendPrivate::transmit(): improve reading from OpenSSL

This patch avoids intermediate copying of the data by writing SSL
decryption data directly into the outer socket's read buffer.

Change-Id: I19e5b6087595f280436a99fb2ca93cc6793c8f36
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
Reviewed-by: Markus Goetz (Woboq GmbH) <markus@woboq.com>
bb10
Alex Trotsenko 2017-07-26 13:39:11 +03:00
parent 1828caad33
commit 8566487286
1 changed files with 5 additions and 4 deletions

View File

@ -756,15 +756,15 @@ void QSslSocketBackendPrivate::transmit()
// we have a readBufferMaxSize. There's no point in leaving data there
// just so that readBuffer.size() == readBufferMaxSize.
int readBytes = 0;
data.resize(4096);
::memset(data.data(), 0, data.size());
const int bytesToRead = 4096;
do {
// Don't use SSL_pending(). It's very unreliable.
if ((readBytes = q_SSL_read(ssl, data.data(), data.size())) > 0) {
readBytes = q_SSL_read(ssl, buffer.reserve(bytesToRead), bytesToRead);
if (readBytes > 0) {
#ifdef QSSLSOCKET_DEBUG
qCDebug(lcSsl) << "QSslSocketBackendPrivate::transmit: decrypted" << readBytes << "bytes";
#endif
buffer.append(data.constData(), readBytes);
buffer.chop(bytesToRead - readBytes);
if (readyReadEmittedPointer)
*readyReadEmittedPointer = true;
@ -773,6 +773,7 @@ void QSslSocketBackendPrivate::transmit()
transmitting = true;
continue;
}
buffer.chop(bytesToRead);
// Error.
switch (q_SSL_get_error(ssl, readBytes)) {