[Qt-interest] QNetworkAccessManager Keep-Alive

Thiago Macieira thiago.macieira at trolltech.com
Thu May 28 12:37:44 CEST 2009


Em Quinta-feira 28 Maio 2009, às 09:28:38, Антон Сердюков escreveu:
> The question is inspired by the lack of documentation on the subject: how
> does the QNetworkAccessManager realize keep-alive mechanism?

Automatically.

> The experiment say: If the reply is deleted (deleteLater really) within
> finished() signal, the connection will be closed.

That's incorrect. The connection will be kept open.

> Otherwise this connection
> is reused for next request. The logic is not obvious.Could someone explain
> the logic more or less clearly? How to make persistent connections work?

The HTTP connection is not tied to the QNetworkReply object. It belongs to the 
QNetworkAccessManager object and is used by the reply only for the duration 
that it needs to.

The manager will keep the connections persistent automatically, without 
intervention by you. If the connection suddenly drops, the manager will 
reconnect automatically as well.

What's more, the manager may keep two connections open per 
hostname/port/protocol combination.

> My application is a server and it needs to send requests to another server
> (IIS) via HTTP. The intervals between requests are indeterminate. I want
> QNetworkAccessManager to establish one or several persistent connections
> and use them for all requests. If connection expires after some idle time -
> it's not problem, it's good. I just don't want to have 10 new outgoing
> connections each second.

Your use-case is handled automatically already. There's nothing you need to 
do.

-- 
Thiago Macieira - thiago.macieira (AT) nokia.com
  Senior Product Manager - Nokia, Qt Software
     Sandakerveien 116, NO-0402 Oslo, Norway
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090528/5bab4782/attachment.bin 


More information about the Qt-interest-old mailing list