]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-34932: Add socket.TCP_KEEPALIVE for macOS (GH-25079)
authorShane Harvey <shnhrv@gmail.com>
Wed, 14 Jul 2021 22:53:15 +0000 (15:53 -0700)
committerGitHub <noreply@github.com>
Wed, 14 Jul 2021 22:53:15 +0000 (23:53 +0100)
Doc/library/socket.rst
Lib/test/test_socket.py
Misc/NEWS.d/next/macOS/2021-03-29-21-11-23.bpo-34932.f3Hdyd.rst [new file with mode: 0644]
Modules/socketmodule.c

index d67df474608d9c27dcdecb1c1afc5029f9f689b8..5634d81cf7e73a642726980025c2f63896f5f983 100755 (executable)
@@ -381,6 +381,8 @@ Constants
 
    .. versionchanged:: 3.10
       ``IP_RECVTOS`` was added.
+       Added ``TCP_KEEPALIVE``. On MacOS this constant can be used in the same
+       way that ``TCP_KEEPIDLE`` is used on Linux.
 
 .. data:: AF_CAN
           PF_CAN
index 828d1f3dcc67012fb471fff57c248417bf1ce1f6..c09f11e0f000fe86b141ebfb7133b2f5d2add268 100755 (executable)
@@ -6446,6 +6446,12 @@ class LinuxKernelCryptoAPI(unittest.TestCase):
             sock.bind(("type", "n" * 64))
 
 
+@unittest.skipUnless(sys.platform == 'darwin', 'macOS specific test')
+class TestMacOSTCPFlags(unittest.TestCase):
+    def test_tcp_keepalive(self):
+        self.assertTrue(socket.TCP_KEEPALIVE)
+
+
 @unittest.skipUnless(sys.platform.startswith("win"), "requires Windows")
 class TestMSWindowsTCPFlags(unittest.TestCase):
     knownTCPFlags = {
@@ -6704,6 +6710,7 @@ def test_main():
         SendfileUsingSendfileTest,
     ])
     tests.append(TestMSWindowsTCPFlags)
+    tests.append(TestMacOSTCPFlags)
 
     thread_info = threading_helper.threading_setup()
     support.run_unittest(*tests)
diff --git a/Misc/NEWS.d/next/macOS/2021-03-29-21-11-23.bpo-34932.f3Hdyd.rst b/Misc/NEWS.d/next/macOS/2021-03-29-21-11-23.bpo-34932.f3Hdyd.rst
new file mode 100644 (file)
index 0000000..d3a52c9
--- /dev/null
@@ -0,0 +1 @@
+Add socket.TCP_KEEPALIVE support for macOS. Patch by Shane Harvey.
index 142cc7c8a7484ec42503cba344afcdf52d314b69..9233430667c2fe4a7481e1b99d610e65a49ff786 100644 (file)
@@ -8158,6 +8158,10 @@ PyInit__socket(void)
 #endif
 #ifdef  TCP_KEEPIDLE
     PyModule_AddIntMacro(m, TCP_KEEPIDLE);
+#endif
+    /* TCP_KEEPALIVE is OSX's TCP_KEEPIDLE equivalent */
+#if defined(__APPLE__) && defined(TCP_KEEPALIVE)
+    PyModule_AddIntMacro(m, TCP_KEEPALIVE);
 #endif
 #ifdef  TCP_KEEPINTVL
     PyModule_AddIntMacro(m, TCP_KEEPINTVL);