summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDon Sanders <don.sanders@nokia.com>2011-11-25 16:10:44 +0200
committerDon Sanders <don.sanders@nokia.com>2011-11-25 16:10:44 +0200
commit2f78dafcdf860771ab1d74186d65aa92d47aeabb (patch)
tree0ccaea020ec68e72cda0b411865f651a63db7c57
parent951cc9c9aeb05d419b892fc68d9afadff9d3699d (diff)
Adjust the pending-data check for ssl sockets.2011W48
Patch form Gabor Fekete. In QSslSocket::encryptedBytesWritten(qint64 written), "written" may be less (or more) than the amount of the original (unencrypted) data. Unfortunately, it seems that QSslSocket::encryptedBytesToWrite() returns 0 both right after writing to the socket (via QDataStream) and also during the QSslSocket::bytesWritten(qint64) signal. This makes it quite impossible to do a reliable bookkeeping of sent data, as is done with QTcpSocket. So, we resort to watching the QSslSocket::encryptedBytesToWrite() and QSslSocket::bytesToWrite() values to detect when all of the data SHOULD have been sent.
-rw-r--r--src/plugins/messageservices/smtp/smtpclient.cpp23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/plugins/messageservices/smtp/smtpclient.cpp b/src/plugins/messageservices/smtp/smtpclient.cpp
index f28b73ed..555cafcb 100644
--- a/src/plugins/messageservices/smtp/smtpclient.cpp
+++ b/src/plugins/messageservices/smtp/smtpclient.cpp
@@ -250,7 +250,7 @@ void SmtpClient::connected(QMailTransport::EncryptType encryptType)
delete authTimeout;
authTimeout = new QTimer;
authTimeout->setSingleShot(true);
- const int twentySeconds = 20 * 1000;
+ const int twentySeconds = 40 * 1000;
connect(authTimeout, SIGNAL(timeout()), this, SLOT(authExpired()));
authTimeout->setInterval(twentySeconds);
authTimeout->start();
@@ -880,6 +880,16 @@ void SmtpClient::sendMoreData(qint64 bytesWritten)
{
Q_ASSERT(status == Body && temporaryFile);
+ // Check if we have any pending data still waiting to be sent.
+#ifndef QT_NO_OPENSSL
+ QSslSocket *socket = qobject_cast<QSslSocket*>(&(transport->socket()));
+ Q_ASSERT(socket);
+ if (socket->encryptedBytesToWrite()
+ || socket->bytesToWrite()) {
+ // There is still pending data to be written.
+ return;
+ }
+#else
waitingForBytes -= bytesWritten;
// If anyone else writes bytes we end up with a negative value... just reset to 0 when that happens.
@@ -887,15 +897,6 @@ void SmtpClient::sendMoreData(qint64 bytesWritten)
// Don't send more data until all bytes have been written.
if (waitingForBytes) return;
-
- // There are more encrypted bytes written than what we send (encryption overhead)
- // but we can't find out exactly how many bytes there are. Now that we think we've
- // written everything, check to see if the connection has any pending encrypted
- // bytes to write and if so, wait for them to be sent.
-#ifndef QT_NO_OPENSSL
- QSslSocket *socket = qobject_cast<QSslSocket*>(&(transport->socket()));
- Q_ASSERT(socket);
- if (socket->encryptedBytesToWrite()) return;
#endif
// No more data to send
@@ -925,7 +926,9 @@ void SmtpClient::sendMoreData(qint64 bytesWritten)
}
}
+#ifdef QT_NO_OPENSSL
waitingForBytes += dotstuffed.length();
+#endif
transport->stream().writeRawData(dotstuffed.constData(), dotstuffed.length());
//qMailLog(SMTP) << "Body: sent a" << bytes << "byte block";
}