tags:

views:

56

answers:

2

I have a QTcpSocket in a seperate thread sending a lot of data. Several of these applications are spread out over the network.

How can I detect whether my network is overloaded and my socket is not able to send anything anymore? Will QTcpSocket buffer all data, how can I see the size of my buffered data that is queueing to be sent? Will this equal bytesToWrite()? Is there a maximum bytesToWrite()?

If QTcpSocket starts discarding data, which data will it be: oldest in buffer queue, newest in buffer queue,...?

+1  A: 

Apparently it doesn't, I just checked the code for Qt 4.5.3. When calling write(), all the data is put in a QRingBuffer (class not part of Qt API). QAbstractData::writeData() puts data in, QAbstractData::flush() pulls it out. There is no check to be found that limits the size of this buffer. The size returned by QAbstractSocket::write() is always either the size of your data or -1 on an error.

Pieter
A: 

QTcpSocket will buffer everything you write into it and will try to write as much as possible the next time the event loop runs. You have to do your own "flow control" by checking socket->bytesToWrite() which tells you how much is still in Qt's buffer (+ there will be additionally data in your OS buffer that you don't have control of)

guruz