10000 [3.14] gh-127840: pass flags and address from send_fds (GH-127841) by miss-islington · Pull Request #134474 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.14] gh-127840: pass flags and address from send_fds (GH-127841) #134474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
gh-127840: pass flags and address from send_fds (GH-127841)
socket: pass flags and address from send_fds
(cherry picked from commit 518c95b)

Co-authored-by: Marcin Bachry <hegel666@gmail.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
  • Loading branch information
2 people authored and miss-islington committed May 22, 2025
commit 82410b61c5ba1a786d76a6e80732ed62696053c7
2 changes: 1 addition & 1 deletion Lib/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
24 changes: 24 additions & 0 deletions Lib/test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix :func:`socket.send_fds` ignoring flags and address parameters.
Loading
0