View Single Post
NerdKnight's Avatar
Posts: 113 | Thanked: 334 times | Joined on Oct 2010 @ Argentina
#4406
Hi Scorpius, I think I found the problem causing Yappari to consume too much CPU, the problem is located here:
Code:
void BinTreeNodeReader::fillArray(QByteArray& buffer, quint32 len)
{
Utilities::logData("Debug: BinTreeNodeReader::fillArray");
    char data[1025];

    buffer.clear();

    // bool ready = true;

    /*
    if (socket->bytesAvailable() < 1)
    {
        Utilities::logData("fillArray() waiting for bytes");
        ready = socket->waitForReadyRead(READ_TIMEOUT);
    }

    if (!ready)
    {
        Utilities::logData("fillArray() not ready / timed out");
        throw IOException(socket->error());
    }
    */

    int needToRead = len;
    while (needToRead > 0)
    {
        Utilities::logData("Debug: BinTreeNodeReader::fillArray--loop");
        int bytesRead = socket->read(data,(needToRead > 1024) ? 1024 : needToRead);

        if (bytesRead < 0)
            throw IOException(socket->error());
        if (bytesRead == 0)
            // socket->waitForReadyRead(READ_TIMEOUT);
            qApp->processEvents();
        else
        {
            needToRead -= bytesRead;
            buffer.append(data,bytesRead);
        }
    }
}
It looks like when there is some sort of connection problem, it nevers exists the while loop and there is no sleep function called, so Yappri eats the CPU. As you can see I added some log messages, when the problem arouse, in minutes the log file grew 26MB large, until I ran out of disk space. I'll patch the code and see if it happens again.