[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: How to move large data inside a protocol over tcp using Qt/KDE?
From:       Thiago Macieira <thiago () kde ! org>
Date:       2008-09-19 6:31:43
Message-ID: 200809190831.43347.thiago () kde ! org
[Download RAW message or body]

[Attachment #2 (multipart/signed)]


Matthew Woehlke wrote:
>Probably Qt polls the socket for you as part of the event loop, hence
>the readyRead signal. Assuming Qt supports non-blocking sockets (which
>it *really* should), you just keep trying to read until you get less
>bytes back than you asked for. Normally you take the little buffers and
>use them to progressively fill a larger buffer until you have an entire
>"message". At that point, you deal with the message, do a memmove to
>shift the buffer contents back to the beginning, and repeat until you
>have reason to stop.

That's how it works.

The sockets are non-blocking, always. And when the function doing the 
reading (QAbstractSocketPrivate::canReadNotification()) is called, it 
will read until it gets a -1 EWOULDBLOCK. When it gets that, it emits 
readyRead().

So readyRead() is emitted once there's data to be read. Unlike a socket 
polling, if you don't read the data, you won't be reminded again. The 
signal emits again only when more data arrives.

-- 
  Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

["signature.asc" (application/pgp-signature)]

>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic