[Interest] QTcpServer memory usage

Bo Thorsen bo at fioniasoftware.dk
Tue Oct 16 16:00:04 CEST 2012

Den 16-10-2012 15:11, Lucas.Betschart at crypto.ch skrev:
> Hi everybody,
> What happens when I have a QTcpServer which gets a connection that writes much data to it (endless), but I never create a QTcpSocket (with QTcpServer::nextPendingConnection() ) and read this data?
> Will I the memory usage of my application increase endless? Or will the QTcpServer just throw away all the data?
> I have to open a port to start an other application, but I'm not interested in the data it sends.

There are finite buffers, so you won't run out of memory. But will the 
client think it's connected before you handle the next pending 
connection? I would have thought you had to create a QTcpSocket before 
the client was happy.

What I don't know is whether or not the client can continue to write 
after the buffer is full, or if it will receive a timeout.

If I were you, I'd probably play this safe and do the 
nextPendingConnection(), and call readAll() when data is ready. Then you 
can just safely forget the returned bytes in readAll.

What you're doing might work, but since it's a non-intended usage you 
might have some odd results. And those might even change between 
versions. Not caring in a nice way can let you stay out of trouble :)


Bo Thorsen.

Come by my DevDays talk in Berlin - "Designing for testability" - and 
learn how to build your unit tests into the Qt applications.

Fionia Software - Qt experts for hire.

More information about the Interest mailing list