You are not logged in.

vdboor

Beginner

  • "vdboor" started this thread

Posts: 30

Location: The Netherlands

Occupation: Software developer

  • Send private message

1

Wednesday, July 6th 2005, 10:49pm

Receiving network file data without blocking the GUI

Hi,

I'm trying to re-implement the file-transfer feature in an MSN client. I receive a continuous data stream from the other contact. How can I read all the data without blocking GUI events? The other contact is transmitting faster then I can process the data.

I'm using a KExtendedSocket to stay compatible to KDE 3.1 environments.
All data is received during the readyRead() signal of the socket.

So far I've tried:
* using a while(socket->bytesAvailable() > 0) to read all data from the buffer. This way I'm chasing a moving target and never exit the loop.
* calling my slot again using QTimer::singleShotTast if there are still bytes available. This improves the GUI responsiveness, but failed when data was received too fast.
* using the processEvents() function. This caused a stack overflow, likely because it was called from a slot.

Does anyone know a working solution (or what is wrong with my early attempts)
Working on KMess, a MSN Messenger client for Linux/KDE.

gadnio

Beginner

Posts: 1

Location: Bulgaria

Occupation: C++/Delphi developer

  • Send private message

2

Thursday, July 7th 2005, 8:17am

RE: Receiving network file data without blocking the GUI

Try using a QThread which is responsible for the transfer. See the docs for details.

vdboor

Beginner

  • "vdboor" started this thread

Posts: 30

Location: The Netherlands

Occupation: Software developer

  • Send private message

3

Thursday, July 7th 2005, 8:47am

Thanks. Will try that.

edit: I found this in the Qt docs:

Quoted

Any operations that generate events must not be called by any thread other than the GUI thread. Examples of such operations are: using a QSocket or other network class.
Working on KMess, a MSN Messenger client for Linux/KDE.

This post has been edited 1 times, last edit by "vdboor" (Jul 7th 2005, 8:58am)


anda_skoa

Professional

Posts: 1,273

Location: Graz, Austria

Occupation: Software Developer

  • Send private message

4

Thursday, July 7th 2005, 9:34am

It shouldn't be a problem to just read when you get the readyRead signal.
KExtendedSocket used buffering internally, so reading whenever you can should be sufficient.

Cheers,
_
Qt/KDE Developer
Debian User

vdboor

Beginner

  • "vdboor" started this thread

Posts: 30

Location: The Netherlands

Occupation: Software developer

  • Send private message

5

Thursday, July 7th 2005, 10:08am

Thanks. I did get this working now.

It appears my processing was slow because I had too much kdDebug() statements in the read-loop. After removing those, my problems disappeared. :O
Working on KMess, a MSN Messenger client for Linux/KDE.