Skip to content

Commit 5cca1b4

Browse files
committed
fix test_send_fds_dontwait on *BSD
1 parent 0134f01 commit 5cca1b4

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Lib/test/test_socket.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7431,20 +7431,27 @@ def test_recv_fds_peek(self):
74317431
self._test_pipe(fds[0], wfd, MSG)
74327432

74337433
@requireAttrs(socket, "MSG_DONTWAIT")
7434-
@unittest.skipUnless(sys.platform in ("linux", "android"), "Linux specific test")
74357434
def test_send_fds_dontwait(self):
74367435
rfd, wfd = os.pipe()
74377436
self.addCleanup(os.close, rfd)
74387437
self.addCleanup(os.close, wfd)
74397438

7440-
sock1, sock2 = socket.socketpair(socket.AF_UNIX, socket.SOCK_DGRAM)
7439+
# use SOCK_STREAM instead of SOCK_DGRAM to support *BSD platforms
7440+
# ref: https://docs.python.org/3/library/asyncio-protocol.html#datagram-protocols
7441+
sock1, sock2 = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM)
74417442
with sock1, sock2:
74427443
sock1.setblocking(True)
74437444
with self.assertRaises(BlockingIOError):
74447445
for _ in range(64 * 1024):
74457446
socket.send_fds(sock1, [MSG], [rfd], socket.MSG_DONTWAIT)
74467447

7447-
msg, fds, flags, addr = socket.recv_fds(sock2, len(MSG), 1)
7448+
if sys.platform.startswith("freebsd"):
7449+
# FreeBSD requires at least CMSG_LEN(2 * sizeof(int)), otherwise
7450+
# the cmsg will be truncated
7451+
recv_fds_len = 2
7452+
else:
7453+
recv_fds_len = 1
7454+
msg, fds, flags, addr = socket.recv_fds(sock2, len(MSG), recv_fds_len)
74487455
self._cleanup_fds(fds)
74497456

74507457
self.assertEqual(msg, MSG)

0 commit comments

Comments
 (0)