summaryrefslogtreecommitdiffstats
path: root/src/network/access/qnetworkrequest.cpp
diff options
context:
space:
mode:
authorMate Barany <mate.barany@qt.io>2025-11-17 17:01:08 +0100
committerMate Barany <mate.barany@qt.io>2025-12-04 14:29:16 +0100
commit135ffa252eec87a396525fdac1b7deaad827ac0a (patch)
treee58411a37f0f02be825c26c55a8ef33c568ba99d /src/network/access/qnetworkrequest.cpp
parent699a39e7fd2e672a33230d3dd3bee902a6b1038d (diff)
Specify TCP Keep Alive parameters via QNetworkRequest
Let the user define the TCP Keep Alive parameters via QNetworkRequest. The default values used by QNetworkAccessManager are defined in QHttpNetworkConnectionChannel and can be overwritten by environment variables. These values can be also controled from the QNetworkRequest API. These have the highest priority. If nothing is defined, QNAM is going to use the default values. If the environmental variables are defined, QNAM is going to use those. If there are values provided via QNetworkRequest, QNAM is going to prefer those. [ChangeLog][QtNetwork][QNetworkRequest] Added new methods to specify and get the current TCP KeepAlive parameters for the request. Task-number: QTBUG-136625 Change-Id: Iafc485eb7b85214500d7c9205db1ecef67dc4b8c Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'src/network/access/qnetworkrequest.cpp')
-rw-r--r--src/network/access/qnetworkrequest.cpp99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp
index 5047fc77bd5..d41124f7b14 100644
--- a/src/network/access/qnetworkrequest.cpp
+++ b/src/network/access/qnetworkrequest.cpp
@@ -475,6 +475,9 @@ public:
decompressedSafetyCheckThreshold = other.decompressedSafetyCheckThreshold;
#endif
transferTimeout = other.transferTimeout;
+ idleTimeBeforeProbes = other.idleTimeBeforeProbes;
+ intervalBetweenProbes = other.intervalBetweenProbes;
+ probeCount = other.probeCount;
}
inline bool operator==(const QNetworkRequestPrivate &other) const
@@ -491,6 +494,9 @@ public:
#endif
&& transferTimeout == other.transferTimeout
&& QHttpHeadersHelper::compareStrict(httpHeaders, other.httpHeaders)
+ && idleTimeBeforeProbes == other.idleTimeBeforeProbes
+ && intervalBetweenProbes == other.intervalBetweenProbes
+ && probeCount == other.probeCount;
;
// don't compare cookedHeaders
}
@@ -508,6 +514,9 @@ public:
qint64 decompressedSafetyCheckThreshold = 10ll * 1024ll * 1024ll;
#endif
std::chrono::milliseconds transferTimeout = 0ms;
+ std::chrono::duration<int> idleTimeBeforeProbes{0};
+ std::chrono::duration<int> intervalBetweenProbes{0};
+ int probeCount = 0;
};
/*!
@@ -1035,6 +1044,96 @@ void QNetworkRequest::setDecompressedSafetyCheckThreshold(qint64 threshold)
}
#endif // QT_CONFIG(http)
+/*!
+ \since 6.11
+
+ Returns the time the connection needs to remain idle before TCP
+ starts sending keepalive probes, if the TCP Keepalive functionality has
+ been turned on.
+
+ \sa setIdleTimeBeforeProbes
+*/
+
+std::chrono::seconds QNetworkRequest::tcpKeepAliveIdleTimeBeforeProbes() const
+{
+ return d->idleTimeBeforeProbes;
+}
+
+/*!
+ \fn void QNetworkRequest::setTcpKeepAliveIdleTimeBeforeProbes(std::chrono::seconds idle)
+ \since 6.11
+
+ Sets the time the connection needs to remain idle before TCP starts
+ sending keepalive probes to be \a idle, if the TCP Keepalive
+ functionality has been turned on.
+
+ \sa idleTimeBeforeProbes
+*/
+
+void QNetworkRequest::doSetIdleTimeBeforeProbes(std::chrono::duration<int> seconds) noexcept
+{
+ d->idleTimeBeforeProbes = seconds;
+}
+
+/*!
+ \since 6.11
+
+ Returns the time between individual keepalive probes, if the TCP
+ Keepalive functionality has been turned on.
+
+ \sa setIntervalBetweenProbes
+*/
+
+std::chrono::seconds QNetworkRequest::tcpKeepAliveIntervalBetweenProbes() const
+{
+ return d->intervalBetweenProbes;
+}
+
+/*!
+ \fn void QNetworkRequest::setTcpKeepAliveIntervalBetweenProbes(std::chrono::seconds interval)
+ \since 6.11
+
+ Sets the time between individual keepalive probes to be \a interval,
+ if the TCP Keepalive functionality has been turned on.
+
+ \sa intervalBetweenProbes
+*/
+
+void QNetworkRequest::doSetIntervalBetweenProbes(std::chrono::duration<int> seconds) noexcept
+{
+ d->intervalBetweenProbes = seconds;
+}
+
+/*!
+ \since 6.11
+
+ Returns the maximum number of keepalive probes TCP should send before
+ dropping the connection, if the TCP Keepalive functionality has been
+ turned on.
+
+ \sa setIntervalBetweenProbes
+*/
+
+int QNetworkRequest::tcpKeepAliveProbeCount() const
+{
+ return d->probeCount;
+}
+
+/*!
+ \since 6.11
+
+ Sets the maximum number of keepalive \a probes TCP should send
+ before dropping the connection, if the TCP Keepalive functionality has
+ been turned on.
+
+ \sa probeCount
+*/
+
+void QNetworkRequest::setTcpKeepAliveProbeCount(int probes) noexcept
+{
+ d->probeCount = probes;
+}
+
#if QT_CONFIG(http) || defined (Q_OS_WASM)
/*!
\fn int QNetworkRequest::transferTimeout() const