[Solved] Read from QSslSocket results irregular data
-
Hi guys,
I read from a QSslSocket to receive yenc encoded usenet articles and save it to files, but something is wrong. Some articles have wrong CRCs while decoding (one "Segment" for each article and file):
@
QSslSocket *sslSocket;
QFile output;void Segment::socketReadyRead() {
const QByteArray data = sslSocket->readAll();output.write(data); if (data.contains("=yend")) { sslSocket->close(); }
}
@What is wrong with my code? Someone has a hint for me?
Thanks!
Kai -
How do you calculate the CRC? How do you do the yEnc decoding? Is it possible that there is data before =ybegin and after =yend?
For example, if readAll() returns "[data]=yend\n" you'll add the whole =yend\n part to output, which might not be expected by the decryption algorithm, and thus corrupt your last data segment. -
The yenc encoding process works after all articles are downloaded, each article in one file. The yenc decoding class works 100% (with correct CRCs), if I download all articles with another program (newsreader/grabber etc.), the yenc decoder decodes it with no errors! ...therefore the problems are in my downloading code!
-
I suggest to add some qDebug() and check if corrupted files have more that one call of Segment::socketReadyRead().
Is it pseudocode?
Why don't you open file before writing with QIODevice::Append mode?
You don't call flush and close on QFile so it's not sure that all data is written to device(some device buffer etc).