https://github.com/python/cpython/commit/518c95b5529ed3379b5a3065b09f71411efe72fb
commit: 518c95b5529ed3379b5a3065b09f71411efe72fb
branch: main
author: Marcin Bachry <hegel...@gmail.com>
committer: gpshead <g...@krypto.org>
date: 2025-05-21T19:38:01-07:00
summary:

gh-127840: pass flags and address from send_fds (GH-127841)

socket: pass flags and address from send_fds

Co-authored-by: Peter Bierma <zintensity...@gmail.com>

files:
A Misc/NEWS.d/next/Library/2024-12-11-20-15-00.gh-issue-127840.pt8fiQ.rst
M Lib/socket.py
M Lib/test/test_socket.py

diff --git a/Lib/socket.py b/Lib/socket.py
index 727b0e75f03595..2cbaf221a59dea 100644
--- a/Lib/socket.py
+++ b/Lib/socket.py
@@ -563,7 +563,7 @@ def send_fds(sock, buffers, fds, flags=0, address=None):
         import array
 
         return sock.sendmsg(buffers, [(_socket.SOL_SOCKET,
-            _socket.SCM_RIGHTS, array.array("i", fds))])
+            _socket.SCM_RIGHTS, array.array("i", fds))], flags, address)
     __all__.append("send_fds")
 
 if hasattr(_socket.socket, "recvmsg"):
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 03c54151a2218f..04dfb682ec6831 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -7366,6 +7366,30 @@ def close_fds(fds):
             data = os.read(rfd, 100)
             self.assertEqual(data,  str(index).encode())
 
+    def testSendAndRecvFdsByAddress(self):
+        rfd, wfd = os.pipe()
+        self.addCleanup(os.close, rfd)
+        self.addCleanup(os.close, wfd)
+
+        sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
+        address = socket_helper.create_unix_domain_name()
+        self.addCleanup(os_helper.unlink, address)
+        socket_helper.bind_unix_socket(sock, address)
+
+        socket.send_fds(sock, [MSG], [rfd], 0, address)
+
+        # request more data and file descriptors than expected
+        msg, (rfd2,), flags, addr = socket.recv_fds(sock, len(MSG) * 2, 2)
+        self.addCleanup(os.close, rfd2)
+        self.assertEqual(msg, MSG)
+        self.assertEqual(flags, 0)
+        self.assertEqual(addr, address)
+
+        # test that the file descriptor is connected
+        os.write(wfd, b'data')
+        data = os.read(rfd2, 100)
+        self.assertEqual(data,  b'data')
+
 
 class FreeThreadingTests(unittest.TestCase):
 
diff --git 
a/Misc/NEWS.d/next/Library/2024-12-11-20-15-00.gh-issue-127840.pt8fiQ.rst 
b/Misc/NEWS.d/next/Library/2024-12-11-20-15-00.gh-issue-127840.pt8fiQ.rst
new file mode 100644
index 00000000000000..51eaaa96ebaa07
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-12-11-20-15-00.gh-issue-127840.pt8fiQ.rst
@@ -0,0 +1 @@
+Fix :func:`socket.send_fds` ignoring flags and address parameters.

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: arch...@mail-archive.com

Reply via email to