Skip to content

Commit 4e4a64b

Browse files
mbachryZeroIntensity
authored andcommitted
pythongh-127840: pass flags and address from send_fds (pythonGH-127841)
socket: pass flags and address from send_fds (cherry picked from commit 518c95b) Co-authored-by: Marcin Bachry <[email protected]> Co-authored-by: Peter Bierma <[email protected]>
1 parent 5ecc39e commit 4e4a64b

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

Lib/socket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ def send_fds(sock, buffers, fds, flags=0, address=None):
557557
Send the list of file descriptors fds over an AF_UNIX socket.
558558
"""
559559
return sock.sendmsg(buffers, [(_socket.SOL_SOCKET,
560-
_socket.SCM_RIGHTS, array.array("i", fds))])
560+
_socket.SCM_RIGHTS, array.array("i", fds))], flags, address)
561561
__all__.append("send_fds")
562562

563563
if hasattr(_socket.socket, "recvmsg"):

Lib/test/test_socket.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7219,6 +7219,30 @@ def close_fds(fds):
72197219
data = os.read(rfd, 100)
72207220
self.assertEqual(data, str(index).encode())
72217221

7222+
def testSendAndRecvFdsByAddress(self):
7223+
rfd, wfd = os.pipe()
7224+
self.addCleanup(os.close, rfd)
7225+
self.addCleanup(os.close, wfd)
7226+
7227+
sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
7228+
address = socket_helper.create_unix_domain_name()
7229+
self.addCleanup(os_helper.unlink, address)
7230+
socket_helper.bind_unix_socket(sock, address)
7231+
7232+
socket.send_fds(sock, [MSG], [rfd], 0, address)
7233+
7234+
# request more data and file descriptors than expected
7235+
msg, (rfd2,), flags, addr = socket.recv_fds(sock, len(MSG) * 2, 2)
7236+
self.addCleanup(os.close, rfd2)
7237+
self.assertEqual(msg, MSG)
7238+
self.assertEqual(flags, 0)
7239+
self.assertEqual(addr, address)
7240+
7241+
# test that the file descriptor is connected
7242+
os.write(wfd, b'data')
7243+
data = os.read(rfd2, 100)
7244+
self.assertEqual(data, b'data')
7245+
72227246

72237247
def setUpModule():
72247248
thread_info = threading_helper.threading_setup()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix :func:`socket.send_fds` ignoring flags and address parameters.

0 commit comments

Comments
 (0)