Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:dfaure
kimap
kimap_waitForReadyRead.diff
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File kimap_waitForReadyRead.diff of Package kimap
diff --git i/src/imapstreamparser.cpp w/src/imapstreamparser.cpp index fb48758..8f49677 100644 --- i/src/imapstreamparser.cpp +++ w/src/imapstreamparser.cpp @@ -25,6 +25,10 @@ #include <ctype.h> #include <QIODevice> +#include <QAbstractSocket> +#include <KTcpSocket> +#include <QDebug> +#include <QElapsedTimer> using namespace KIMAP; @@ -48,11 +52,11 @@ QByteArray ImapStreamParser::readString() { QByteArray result; if (!waitForMoreData(m_data.isEmpty())) { - throw ImapParserException("Unable to read more data"); + throw ImapParserException("Unable to read more data (ReadString)"); } stripLeadingSpaces(); if (!waitForMoreData(m_position >= m_data.length())) { - throw ImapParserException("Unable to read more data"); + throw ImapParserException("Unable to read more data (ReadString 2)"); } // literal string @@ -71,7 +75,7 @@ QByteArray ImapStreamParser::readString() bool ImapStreamParser::hasString() { if (!waitForMoreData(m_position >= m_data.length())) { - throw ImapParserException("Unable to read more data"); + throw ImapParserException("Unable to read more data (hasString)"); } int savedPos = m_position; stripLeadingSpaces(); @@ -98,7 +102,7 @@ bool ImapStreamParser::hasString() bool ImapStreamParser::hasLiteral() { if (!waitForMoreData(m_position >= m_data.length())) { - throw ImapParserException("Unable to read more data"); + throw ImapParserException("Unable to read more data (hasLiteral)"); } int savedPos = m_position; stripLeadingSpaces(); @@ -107,7 +111,7 @@ bool ImapStreamParser::hasLiteral() do { end = m_data.indexOf('}', m_position); if (!waitForMoreData(end == -1)) { - throw ImapParserException("Unable to read more data"); + throw ImapParserException("Unable to read more data (hasLiteral)"); } } while (end == -1); Q_ASSERT(end > m_position); @@ -116,7 +120,7 @@ bool ImapStreamParser::hasLiteral() m_position = end + 1; // ensure that the CRLF is available if (!waitForMoreData(m_position + 1 >= m_data.length())) { - throw ImapParserException("Unable to read more data"); + throw ImapParserException("Unable to read more data (hasLiteral)"); } if (m_position < m_data.length() && m_data.at(m_position) == '\r') { ++m_position; @@ -147,7 +151,7 @@ QByteArray ImapStreamParser::readLiteralPart() int size = qMin(maxLiteralPartSize, m_literalSize); if (!waitForMoreData(m_data.length() < m_position + size)) { - throw ImapParserException("Unable to read more data"); + throw ImapParserException("Unable to read more data (readLiteralPart)"); } if (m_data.length() < m_position + size) { // Still not enough data @@ -167,7 +171,7 @@ QByteArray ImapStreamParser::readLiteralPart() bool ImapStreamParser::hasList() { if (!waitForMoreData(m_position >= m_data.length())) { - throw ImapParserException("Unable to read more data"); + throw ImapParserException("Unable to read more data (hasList)"); } int savedPos = m_position; stripLeadingSpaces(); @@ -182,7 +186,7 @@ bool ImapStreamParser::hasList() bool ImapStreamParser::atListEnd() { if (!waitForMoreData(m_position >= m_data.length())) { - throw ImapParserException("Unable to read more data"); + throw ImapParserException("Unable to read more data (atListEnd)"); } int savedPos = m_position; stripLeadingSpaces(); @@ -199,7 +203,7 @@ QList<QByteArray> ImapStreamParser::readParenthesizedList() { QList<QByteArray> result; if (!waitForMoreData(m_data.length() <= m_position)) { - throw ImapParserException("Unable to read more data"); + throw ImapParserException("Unable to read more data (readParenthesizedList)"); } stripLeadingSpaces(); @@ -215,7 +219,7 @@ QList<QByteArray> ImapStreamParser::readParenthesizedList() if (!waitForMoreData(m_data.length() <= i)) { m_position = i; - throw ImapParserException("Unable to read more data"); + throw ImapParserException("Unable to read more data (readParenthesizedList 2)"); } if (m_data.at(i) == '(') { @@ -305,7 +309,7 @@ QList<QByteArray> ImapStreamParser::readParenthesizedList() bool ImapStreamParser::hasResponseCode() { if (!waitForMoreData(m_position >= m_data.length())) { - throw ImapParserException("Unable to read more data"); + throw ImapParserException("Unable to read more data (hasResponseCode)"); } int savedPos = m_position; stripLeadingSpaces(); @@ -321,7 +325,7 @@ bool ImapStreamParser::hasResponseCode() bool ImapStreamParser::atResponseCodeEnd() { if (!waitForMoreData(m_position >= m_data.length())) { - throw ImapParserException("Unable to read more data"); + throw ImapParserException("Unable to read more data (atResponseCodeEnd)"); } int savedPos = m_position; stripLeadingSpaces(); @@ -338,16 +342,16 @@ QByteArray ImapStreamParser::parseQuotedString() { QByteArray result; if (!waitForMoreData(m_data.length() == 0)) { - throw ImapParserException("Unable to read more data"); + throw ImapParserException("Unable to read more data (parseQuotedString)"); } stripLeadingSpaces(); int end = m_position; result.clear(); if (!waitForMoreData(m_position >= m_data.length())) { - throw ImapParserException("Unable to read more data"); + throw ImapParserException("Unable to read more data (parseQuotedString 2)"); } if (!waitForMoreData(m_position >= m_data.length())) { - throw ImapParserException("Unable to read more data"); + throw ImapParserException("Unable to read more data (parseQuotedString 3)"); } bool foundSlash = false; @@ -359,7 +363,7 @@ QByteArray ImapStreamParser::parseQuotedString() if (!waitForMoreData(m_data.length() <= i)) { m_position = i; - throw ImapParserException("Unable to read more data"); + throw ImapParserException("Unable to read more data (loop)"); } if (m_data.at(i) == '\\') { @@ -385,7 +389,7 @@ QByteArray ImapStreamParser::parseQuotedString() if (!waitForMoreData(m_data.length() <= i)) { m_position = i; - throw ImapParserException("Unable to read more data"); + throw ImapParserException("Unable to read more data (391)"); } if (m_data.at(i) == ' ' || m_data.at(i) == '(' || @@ -433,21 +437,22 @@ qint64 ImapStreamParser::readNumber(bool *ok) *ok = false; } if (!waitForMoreData(m_data.length() == 0)) { - throw ImapParserException("Unable to read more data"); + throw ImapParserException("Unable to read more data (readNumber)"); } stripLeadingSpaces(); if (!waitForMoreData(m_position >= m_data.length())) { - throw ImapParserException("Unable to read more data"); + throw ImapParserException("Unable to read more data (readNumber 2)"); } if (m_position >= m_data.length()) { - throw ImapParserException("Unable to read more data"); + qWarning() << "m_position=" << m_position << "=>" << m_data.length(); + throw ImapParserException("Unable to read more data (readNumber 3 - NOT waitForMoreData)"); } int i = m_position; Q_FOREVER { if (!waitForMoreData(m_data.length() <= i)) { m_position = i; - throw ImapParserException("Unable to read more data"); + throw ImapParserException("Unable to read more data (readNumber loop)"); } if (!isdigit(m_data.at(i))) { @@ -475,10 +480,21 @@ void ImapStreamParser::stripLeadingSpaces() bool ImapStreamParser::waitForMoreData(bool wait) { if (wait) { + QElapsedTimer dt; + if (m_socket->bytesAvailable() == 0) { + dt.start(); + } if (m_socket->bytesAvailable() > 0 || - m_socket->waitForReadyRead(30000)) { + m_socket->waitForReadyRead(300000)) { // 5 minutes m_data.append(m_socket->readAll()); } else { + if (QAbstractSocket *socket = qobject_cast<QAbstractSocket *>(m_socket)) { + qWarning() << "No incoming packet for" << dt.elapsed()/1000 << "seconds on IMAP socket. state=" << socket->state() << "error=" << socket->error() << socket->errorString(); + } else if (KTcpSocket *socket = qobject_cast<KTcpSocket *>(m_socket)) { + qWarning() << "No incoming packet for" << dt.elapsed()/1000 << "seconds on TCP socket. state=" << socket->state() << "error=" << socket->error() << socket->errorString(); + } else { + qWarning() << "No incoming packet for" << dt.elapsed()/1000 << "seconds on device" << m_socket; + } return false; } } @@ -505,7 +521,7 @@ bool ImapStreamParser::atCommandEnd() int savedPos = m_position; do { if (!waitForMoreData(m_position >= m_data.length())) { - throw ImapParserException("Unable to read more data"); + throw ImapParserException("Unable to read more data (atCommandEnd)"); } stripLeadingSpaces(); } while (m_position >= m_data.size()); @@ -536,7 +552,7 @@ QByteArray ImapStreamParser::readUntilCommandEnd() if (!waitForMoreData(m_data.length() <= i)) { m_position = i; - throw ImapParserException("Unable to read more data"); + throw ImapParserException("Unable to read more data (readUntilCommandEnd)"); } if (m_data.at(i) == '{') {
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor