summaryrefslogtreecommitdiffstats
path: root/src/network/socket/qnativesocketengine_unix.cpp
diff options
context:
space:
mode:
authorMate Barany <mate.barany@qt.io>2025-11-10 17:44:18 +0100
committerMate Barany <mate.barany@qt.io>2025-11-25 17:02:22 +0100
commitf216d13b67b9fb73c50593d7ab0047dc3b50805e (patch)
treecaed4e6f8318902d26c44fc7a36e83d0d178aacf /src/network/socket/qnativesocketengine_unix.cpp
parent5c7b5d151894c39af07234563edd101da33bafde (diff)
Add TCP Keepalive options to QAbstractSocket
TCP Keepalive is turned on for QNAM but it is using the default system values. On Linux this means that it takes 131 minutes to tear down the connection. This can be customized with the values of TCP_KEEPIDLE - how long do we wait before we send probes TCP_KEEPINTVL - the time interval between two probes TCP_KEEPCNT - the number of probes sent So extend Qabstractsocket with the following socketoptions: KeepAliveIdleOption (TCP_KEEPIDLE) KeepAliveIntervalOption (TCP_KEEPINTVL) KeepAliveCountOption (TCP_KEEPCNT) Not all platforms provide the same support for these parameters. What we know: On Linux, all of the above is supported. On Windows, these are supported since Windows 10, 1709. On Mac all of the above is supported but TCP_KEEPIDLE is called TCP_KEEPALIVE. On QNX 7.1 only TCP_KEEPIDLE is supported and it is called as TCP_KEEPALIVE. On QNX 8.0 all of the above is supported and TCP_KEEPIDLE is called TCP_KEEPIDLE. MinGW also supports all of the above from version 12, but it seems that we have an older version in the CI so we need some ifdefs. VxWorks also supports TCP_KEEPIDLE, TCP_KEEPCNT and TCP_KEEPINTVL. [ChangeLog][QtNetwork][QAbstractSocket] Added new socketoptions to QAbstractSocket: KeepAliveIdleOption, KeepAliveIntervalOption and KeepAliveCountOption. Task-number: QTBUG-136625 Change-Id: I89d1788a19719da10ce740b52b2a6570680e0f5d Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/network/socket/qnativesocketengine_unix.cpp')
-rw-r--r--src/network/socket/qnativesocketengine_unix.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/network/socket/qnativesocketengine_unix.cpp b/src/network/socket/qnativesocketengine_unix.cpp
index a19223e2348..e920de11c13 100644
--- a/src/network/socket/qnativesocketengine_unix.cpp
+++ b/src/network/socket/qnativesocketengine_unix.cpp
@@ -170,6 +170,26 @@ static void convertToLevelAndOption(QNativeSocketEngine::SocketOption opt,
#endif
}
break;
+ case QNativeSocketEngine::KeepAliveIdleOption:
+ level = IPPROTO_TCP;
+#ifdef TCP_KEEPALIVE
+ n = TCP_KEEPALIVE;
+#else
+ n = TCP_KEEPIDLE;
+#endif
+ break;
+ case QNativeSocketEngine::KeepAliveIntervalOption:
+#ifdef TCP_KEEPINTVL
+ level = IPPROTO_TCP;
+ n = TCP_KEEPINTVL;
+#endif
+ break;
+ case QNativeSocketEngine::KeepAliveCountOption:
+#ifdef TCP_KEEPCNT
+ level = IPPROTO_TCP;
+ n = TCP_KEEPCNT;
+#endif
+ break;
}
}