Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[qmf] Prevents POP3/SMTP incoming data read from stopping when handli…
…ng large requests.

Keeps reading available data from the socket even if not a entire line is available,
this way readyRead signals will be emitted when new data arrives in the socket.
  • Loading branch information
Valerio Valerio committed Jul 16, 2014
1 parent 0e55361 commit 0f34a51
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
33 changes: 22 additions & 11 deletions qmf/src/plugins/messageservices/pop/popclient.cpp
Expand Up @@ -478,23 +478,34 @@ void PopClient::sendCommand(const QByteArray& cmd)
sendCommand(cmd.data(), cmd.length());
}

QString PopClient::readResponse()
void PopClient::incomingData()
{
QString response = QString::fromLatin1(transport->readLine());

if ((response.length() > 1) && (status != MessageDataRetr) && (status != MessageDataTop)) {
qMailLog(POP) << "RECV:" << qPrintable(response.left(response.length() - 2));
bool processIncompleteLine = false;
if (!lineBuffer.isEmpty() && transport->canReadLine()) {
processIncompleteLine = true;
}

return response;
}

void PopClient::incomingData()
{
while (transport && transport->canReadLine()) {
QString response = readResponse();
QString response;
if (processIncompleteLine) {
processIncompleteLine = false;
response = QString::fromLatin1(lineBuffer + transport->readLine());
lineBuffer.clear();
} else {
response = QString::fromLatin1(transport->readLine());
}

if ((response.length() > 1) && (status != MessageDataRetr) && (status != MessageDataTop)) {
qMailLog(POP) << "RECV:" << qPrintable(response.left(response.length() - 2));
}

processResponse(response);
}

if (transport->bytesAvailable()) {
// If there is an incomplete line, read it from the socket buffer to ensure we get readyRead signal next time
lineBuffer.append(transport->readAll());
}
}

void PopClient::processResponse(const QString &response)
Expand Down
3 changes: 2 additions & 1 deletion qmf/src/plugins/messageservices/pop/popclient.h
Expand Up @@ -99,6 +99,7 @@ class PopClient : public QObject
#endif

signals:
void connectionError(QMailServiceAction::Status::ErrorCode status, const QString &msg);
void errorOccurred(int, const QString &);
void errorOccurred(QMailServiceAction::Status::ErrorCode, const QString &);
void updateStatus(const QString &);
Expand Down Expand Up @@ -138,7 +139,6 @@ protected slots:
void sendCommand(const char *data, int len = -1);
void sendCommand(const QString& cmd);
void sendCommand(const QByteArray& cmd);
QString readResponse();
void processResponse(const QString &response);
void nextAction();
void retrieveOperationCompleted();
Expand Down Expand Up @@ -184,6 +184,7 @@ protected slots:
LongStream *dataStream;

QMailTransport *transport;
QByteArray lineBuffer;

QString retrieveUid;

Expand Down
19 changes: 18 additions & 1 deletion qmf/src/plugins/messageservices/smtp/smtpclient.cpp
Expand Up @@ -393,8 +393,20 @@ void SmtpClient::sendCommands(const QStringList &cmds)

void SmtpClient::incomingData()
{
bool processIncompleteLine = false;
if (!lineBuffer.isEmpty() && transport->canReadLine()) {
processIncompleteLine = true;
}

while (transport->canReadLine()) {
QString response = transport->readLine();
QString response;
if (processIncompleteLine) {
processIncompleteLine = false;
response = QString::fromLatin1(lineBuffer + transport->readLine());
lineBuffer.clear();
} else {
response = QString::fromLatin1(transport->readLine());
}
qMailLog(SMTP) << "RECV:" << response.left(response.length() - 2) << flush;

delete authTimeout;
Expand Down Expand Up @@ -422,6 +434,11 @@ void SmtpClient::incomingData()
nextAction(response);
}
}

if (transport->bytesAvailable()) {
// If there is an incomplete line, read it from the socket buffer to ensure we get readyRead signal next time
lineBuffer.append(transport->readAll());
}
}

void SmtpClient::nextAction(const QString &response)
Expand Down
2 changes: 2 additions & 0 deletions qmf/src/plugins/messageservices/smtp/smtpclient.h
Expand Up @@ -88,6 +88,7 @@ class SmtpClient : public QObject
QMailServiceAction::Status::ErrorCode addMail(const QMailMessage& mail);

signals:
void connectionError(QMailServiceAction::Status::ErrorCode status, const QString &msg);
void errorOccurred(int, const QString &);
void errorOccurred(const QMailServiceAction::Status &, const QString &);
void updateStatus(const QString &);
Expand Down Expand Up @@ -151,6 +152,7 @@ private slots:
int outstandingResponses;
QStringList::Iterator it;
QMailTransport *transport;
QByteArray lineBuffer;

// SendMap maps id -> (units) to be sent
typedef QMap<QMailMessageId, uint> SendMap;
Expand Down

0 comments on commit 0f34a51

Please sign in to comment.