[Interest] QTcpServer memory usage

Thiago Macieira thiago.macieira at intel.com
Tue Oct 16 17:00:57 CEST 2012


On terça-feira, 16 de outubro de 2012 15.11.23, Lucas.Betschart at crypto.ch 
wrote:
> 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.

Answering the question "what happens if QTcpSocket is not created":

if the QTcpSocket is not created, the socket is sitting in the kernel, in 
accepted mode, even if the application hasn't yet called accept(2). It will 
also begin receiving data from the peer. However, those buffers belong to the 
kernel and they are quite small (usually less than 64k). Soon after, the TCP 
stack will stop sending ACKs and the peer will have to stop sending.

In other words, there's no memory increase in your application if the 
QTcpSocket isn't created.

However, your email has a problem, since it contradicts itself:

Answering the question "what happens if I don't call nextPendingConnection":

nextPendingConnection does not create the QTcpSocket. It has been created 
already, which means QTcpSocket's unlimited buffer is already receiving data. 
That also means your application's memory usage will increase if the sender is 
sending data.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20121016/08841ac9/attachment.sig>


More information about the Interest mailing list