Ok, it turned out the socket's buffer was growing uncontrollably because data was being fed to it faster than it could be flushed.
I fixed the problem by checking the value given by bytesWritten
, and writing only so much bytes (in effect, refilling the buffer back to 64k).
My fixed code now looks like this:
void AsynchronousRetrieveCommand::start()
{
connect(socket(), SIGNAL(bytesWritten(qint64)), this, SLOT(sendNextBlock(qint64)));
sendNextBlock(64*1024);
}
void AsynchronousRetrieveCommand::sendNextBlock(qint64 bytes)
{
socket()->write(file->read(bytes));
}