[Qt-interest] Socket communication without threads

Arnold Krille arnold at arnoldarts.de
Tue Mar 3 20:41:22 CET 2009


Hi,

On Tuesday 03 March 2009 18:35:54 Roland Krause wrote:
> There is an additional problem here with the block size at least for
> QLocalSocket. I've been experimenting with it and noticed that if you send
> a large block of data at a time, you have to manually process events in
> order to receive all the data in one go. It seems that the readyRead signal
> is emitted and when you call read(char * data, quint64  size) you can only
> get as much data as was in the buffer at the time of the call which must
> not necessarily be all the data that was written.

You really expect the network driver or glibc or Qt to have buffers in memory 
of several hundred megabytes???

> I am going to try the same with QTcpSocket next and see whether the problem
> is the same there (it should afaict from looking at the implementation of
> QLocalSocket).
> Anyway, I believe for large amounts of payload data a threaded
> implementation could be warranted.

Still no need for threads. Just create your own buffer which you append data to 
inside the slot connected to readyRead(). Once a full dataset is in the buffer 
you can trigger processing (while the next dataset might be appended by 
readyRead()). Why would you want several (explicit) threads when you already 
have several apps (the same as threads only they each have their own memory 
section)?

Arnold
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090303/647768b9/attachment.bin 


More information about the Qt-interest-old mailing list