Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
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
39 changes: 39 additions & 0 deletions Lib/test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -7071,6 +7071,45 @@ def close_fds(fds):
data = os.read(rfd, 100)
self.assertEqual(data, str(index).encode())

def testSendAndRecvFdsByAddress(self):
def close_pipes(pipes):
for fd1, fd2 in pipes:
os.close(fd1)
os.close(fd2)

def close_fds(fds):
for fd in fds:
os.close(fd)

# send 10 file descriptors
pipes = [os.pipe() for _ in range(10)]
self.addCleanup(close_pipes, pipes)
fds = [rfd for rfd, wfd in pipes]

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], fds, 0, address)

# request more data and file descriptors than expected
msg, fds2, flags, addr = socket.recv_fds(sock, len(MSG) * 2, len(fds) * 2)
self.addCleanup(close_fds, fds2)

self.assertEqual(msg, MSG)
self.assertEqual(len(fds2), len(fds))
self.assertEqual(flags, 0)

# test that file descriptors are connected
for index, fds in enumerate(pipes):
rfd, wfd = fds
os.write(wfd, str(index).encode())

for index, rfd in enumerate(fds2):
data = os.read(rfd, 100)
self.assertEqual(data, str(index).encode())


def setUpModule():
thread_info = threading_helper.threading_setup()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix ``socket.send_fds`` ignoring flags and address parameters
Loading