Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Read from QSslSocket results irregular data
Forum Update on Monday, May 27th 2025

[Solved] Read from QSslSocket results irregular data

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 3.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dynup
    wrote on 10 Jun 2012, 16:41 last edited by
    #1

    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

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DerManu
      wrote on 11 Jun 2012, 13:07 last edited by
      #2

      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.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dynup
        wrote on 11 Jun 2012, 13:41 last edited by
        #3

        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!

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tolszak
          wrote on 11 Jun 2012, 15:23 last edited by
          #4

          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).

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dynup
            wrote on 11 Jun 2012, 18:26 last edited by
            #5

            It's not a part for this sample here. File will open before connect to host and closed after socket is closed (in other functions)! Segment::socketReadyRead() is called multiple times of course, it's a TCP based connection.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DerManu
              wrote on 11 Jun 2012, 19:11 last edited by
              #6

              I still wonder whether there's data after "=yend", since you just use readAll and push that into output without truncating after "=yend"...

              1 Reply Last reply
              0
              • D Offline
                D Offline
                dynup
                wrote on 11 Jun 2012, 20:52 last edited by
                #7

                =yend is part of last data block, after this article ends.

                Last line of each article is:
                =yend size=<...> part=<lastPartNumber> pcrc32=<crc>

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  dynup
                  wrote on 12 Jun 2012, 10:16 last edited by
                  #8

                  Addition:

                  pcrc32=<8 char hexvalue> Representing the 8-bit CRC32 of the encoded binary part
                  crc32=<8 char hexvalue> Representing the 8-bit CRC32 of the encoded binary

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    dynup
                    wrote on 12 Jun 2012, 17:48 last edited by
                    #9

                    I found the (simple) problem!

                    In NNTP protocol some lines (I read line by line now) begins with a double-dot, this must detect and replace with a single dot, that's it! All CRCs are conform now!

                    Thanks to all for help anyway!

                    1 Reply Last reply
                    0

                    1/9

                    10 Jun 2012, 16:41

                    • Login

                    • Login or register to search.
                    1 out of 9
                    • First post
                      1/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved