diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/network/doc/src/http.qdoc | 9 | ||||
| -rw-r--r-- | examples/network/http/httpwindow.cpp | 11 |
2 files changed, 19 insertions, 1 deletions
diff --git a/examples/network/doc/src/http.qdoc b/examples/network/doc/src/http.qdoc index a07d0fe73b0..e8ebc907e92 100644 --- a/examples/network/doc/src/http.qdoc +++ b/examples/network/doc/src/http.qdoc @@ -18,6 +18,15 @@ The main work of this example is done in the HttpWindow class. Thus we will focus on that. + \snippet http/httpwindow.cpp qnam-tcpkeepalive + + Since Qt 6.11, it is possible to explicitly specify the TCP keepalive + parameters for a QNetworkRequest. In the snippet above, we are overriding + the defaults used by QNetworkAccessManager to follow a more aggressive + strategy. This can be useful, for example, in early detection of network + hangs caused by network changes on Linux. In this particular example, the + connection will be closed after thirty seconds of inactivity. + \snippet http/httpwindow.cpp qnam-download Using QNetworkAccessManager, we begin the download of a resource as diff --git a/examples/network/http/httpwindow.cpp b/examples/network/http/httpwindow.cpp index 3d1c2467d84..3a4ae098321 100644 --- a/examples/network/http/httpwindow.cpp +++ b/examples/network/http/httpwindow.cpp @@ -10,6 +10,8 @@ #include <QUrl> #include <memory> +#include <chrono> +using namespace std::chrono_literals; #if QT_CONFIG(ssl) const char defaultUrl[] = "https://www.qt.io/"; @@ -95,8 +97,15 @@ void HttpWindow::startRequest(const QUrl &requestedUrl) url = requestedUrl; httpRequestAborted = false; + //! [qnam-tcpkeepalive] + QNetworkRequest networkRequest(url); + networkRequest.setTcpKeepAliveIdleTimeBeforeProbes(20s); + networkRequest.setTcpKeepAliveIntervalBetweenProbes(2s); + networkRequest.setTcpKeepAliveProbeCount(5); + //! [qnam-tcpkeepalive] + //! [qnam-download] - reply.reset(qnam.get(QNetworkRequest(url))); + reply.reset(qnam.get(networkRequest)); //! [qnam-download] //! [connecting-reply-to-slots] connect(reply.get(), &QNetworkReply::finished, this, &HttpWindow::httpFinished); |
